PHP json_encode中文亂碼問(wèn)題的解決辦法
更新時(shí)間:2013年09月09日 16:59:35 作者:
這篇文章介紹了PHP json_encode中文亂碼問(wèn)題的解決辦法,有需要的朋友可以參考一下
下面的PHP代碼可以解決以下問(wèn)題:
1.json_encode UTF8碼中文后的字符串不可閱讀
2.json_encode 多級(jí)數(shù)組中文亂碼問(wèn)題
3.json_encode 數(shù)組中包含換行時(shí)錯(cuò)誤問(wèn)題
4.json_encode 數(shù)組中鍵為中文的問(wèn)題
function _encode($arr)
{
$na = array();
foreach ( $arr as $k => $value ) {
$na[_urlencode($k)] = _urlencode ($value);
}
return addcslashes(urldecode(json_encode($na)),"\\r\\n");
}
function _urlencode($elem)
{
if(is_array($elem)){
foreach($elem as $k=>$v){
$na[_urlencode($k)] = _urlencode($v);
}
return $na;
}
return urlencode($elem);
}
1.json_encode UTF8碼中文后的字符串不可閱讀
2.json_encode 多級(jí)數(shù)組中文亂碼問(wèn)題
3.json_encode 數(shù)組中包含換行時(shí)錯(cuò)誤問(wèn)題
4.json_encode 數(shù)組中鍵為中文的問(wèn)題
復(fù)制代碼 代碼如下:
function _encode($arr)
{
$na = array();
foreach ( $arr as $k => $value ) {
$na[_urlencode($k)] = _urlencode ($value);
}
return addcslashes(urldecode(json_encode($na)),"\\r\\n");
}
function _urlencode($elem)
{
if(is_array($elem)){
foreach($elem as $k=>$v){
$na[_urlencode($k)] = _urlencode($v);
}
return $na;
}
return urlencode($elem);
}
您可能感興趣的文章:
- PHP json_encode() 函數(shù)詳解及中文亂碼問(wèn)題
- php中json_encode UTF-8中文亂碼的更好解決方法
- php中json_encode處理gbk與gb2312中文亂碼問(wèn)題的解決方法
- 解決zabbix監(jiān)控因php問(wèn)題導(dǎo)致圖形界面中文亂碼方法
- php寫(xiě)入mysql中文亂碼的實(shí)例解決方法
- PHP基于curl post實(shí)現(xiàn)發(fā)送url及相關(guān)中文亂碼問(wèn)題解決方法
- php中文亂碼問(wèn)題的終極解決方案匯總
- PHP讀MYSQL中文亂碼的快速解決方法
- Linux php 中文亂碼的快速解決方法
- PHP讀取mssql json數(shù)據(jù)中文亂碼的解決辦法
- PHP中使用substr()截取字符串出現(xiàn)中文亂碼問(wèn)題該怎么辦
- PHP+MYSQL中文亂碼問(wèn)題
- PHP json_encode中文亂碼解決方法
相關(guān)文章
啟用Csrf后POST數(shù)據(jù)時(shí)出現(xiàn)的400錯(cuò)誤
這篇文章主要介紹了啟用Csrf后POST數(shù)據(jù)時(shí)出現(xiàn)的400錯(cuò)誤的相關(guān)資料,需要的朋友可以參考下2015-07-07php實(shí)現(xiàn)MySQL數(shù)據(jù)庫(kù)備份與還原類實(shí)例
這篇文章主要介紹了php實(shí)現(xiàn)MySQL數(shù)據(jù)庫(kù)備份與還原類,可實(shí)現(xiàn)針對(duì)MySQL數(shù)據(jù)庫(kù)的導(dǎo)入與導(dǎo)出功能,并且包含了針對(duì)數(shù)據(jù)庫(kù)操作時(shí)的加鎖與解鎖等功能,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-12-12CodeIgniter生成網(wǎng)站sitemap地圖的方法
用CodeIgniter只需要三步就可以生成網(wǎng)站sitemap地圖,方法很簡(jiǎn)單,大家可以參考一下2013-11-11PHP商品秒殺問(wèn)題解決方案實(shí)例詳解【mysql與redis】
這篇文章主要介紹了PHP商品秒殺問(wèn)題解決方案,結(jié)合實(shí)例形式詳細(xì)分析了php結(jié)合mysql與redis實(shí)現(xiàn)商品秒殺功能的相關(guān)操作技巧及注意事項(xiàng),需要的朋友可以參考下2019-07-07PHP實(shí)現(xiàn)多個(gè)關(guān)鍵詞搜索查詢功能示例
這篇文章主要介紹了PHP實(shí)現(xiàn)多個(gè)關(guān)鍵詞搜索查詢功能,結(jié)合實(shí)例形式分析了php使用mysql中l(wèi)ike、union等語(yǔ)句模糊查詢相關(guān)操作技巧,需要的朋友可以參考下2018-06-06