1.命令行下将unicode转中文?
<code><span><?php </span><span><span>function</span><span>unicodeDecode</span><span>(<span>$name</span>)</span>{</span><span>$json</span> = <span>'{"str":"'</span>.<span>$name</span>.<span>'"}'</span>; <span>$arr</span> = json_decode(<span>$json</span>,<span>true</span>); <span>if</span>(<span>empty</span>(<span>$arr</span>)) <span>return</span><span>''</span>; <span>return</span><span>$arr</span>[<span>'str'</span>]; } <span>$name</span> = <span>'\u65b0\u6d6a\u5fae\u535a'</span>; <span>echo</span> unicodeDecode(<span>$name</span>); <span>//输出: 新浪微博 </span></span></code>
<code><span><span>function</span><span>replace_unicode_escape_sequence</span><span>(<span>$match</span>)</span> {</span><span>return</span> mb_convert_encoding(pack(<span>'H*'</span>, <span>$match</span>[<span>1</span>]), <span>'UTF-8'</span>, <span>'UCS-2BE'</span>); } <span>$name</span> = <span>'\u65b0\u6d6a\u5fae\u535a'</span>; <span>$str</span> = preg_replace_callback(<span>'/\\\\u([0-9a-f]{4})/i'</span>, <span>'replace_unicode_escape_sequence'</span>, <span>$name</span>); <span>echo</span><span>$str</span>; <span>//输出: 新浪微博 </span></code>
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了php踩坑记录持续更新,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。