php utf-8字符轉ascii字符


function utf8_urldecode($str) 

{
$str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str));
return html_entity_decode($str,null,'UTF-8');;
}

function ConvertUTF8ToGB2312($str)
{
return iconv("UTF-8","GB2312//IGNORE",$str);
}

function ConvertGB2312ToUTF8($str)
{
return iconv("GB2312","UTF-8//IGNORE",$str);
}

php處理環境是utf-8的, jquery所在網頁也是的utf-8的, jquery post的中文數據以%u開頭, 需要將這個code轉發到另一台接收gb2312字符的web網站

if(isset($_REQUEST["code"]))
{
    //解碼
    $tmp = utf8_urldecode($_REQUEST["code"]);
    //utf-8轉gb2312
    $tmp = ConvertUTF8ToGB2312($tmp);
    //編碼
    $tmp = urlencode($tmp);
    $AppendPara .= "&code=" . $tmp;
}
else
{
    $AppendPara .= "&code=";
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM