久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      如何解決php中文轉(zhuǎn)碼的問題

      如何解決php中文轉(zhuǎn)碼的問題

      php 解決json_encode中文UNICODE轉(zhuǎn)碼問題

      用PHP的json_encode來處理中文的時候, 中文都會被編碼, 變成不可讀的, 類似”u***”的格式,如果想漢字不進行轉(zhuǎn)碼,這里提供三種方法

      1.升級PHP,在PHP5.4, 這個問題終于得以解決, Json新增了一個選項: JSON_UNESCAPED_UNICODE, 故名思議, 就是說, Json不要編碼Unicode.

      <?php echo json_encode("中文", JSON_UNESCAPED_UNICODE); //"中文"

      2.把漢字先urlencode然后再使用json_encode,json_encode之后再次使用urldecode來解碼,這樣編碼出來的json數(shù)組中的漢字就不會出現(xiàn)unicode編碼了。

      $array = array( 'test'=>urlencode("我是測試") ); $array = json_encode($array); echo urldecode($array); //{"test":"我是測試"}

      3.對unicode碼再進行解碼,解碼函數(shù)如下:

      function decodeUnicode($str) {     return preg_replace_callback('/\\u([0-9a-f]{4})/i',         create_function(             '$matches',             'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");'         ),          $str); }

      4.例子

      $arr = array('name1':"中文",'name2':'abc12'); $jsonstr = decodeUnicode(json_encode($arr));

      推薦教程:《PHP教程》

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號