Home >php教程 >PHP源码 >php js的unicode的url编码和php转换

php js的unicode的url编码和php转换

PHP中文网
PHP中文网Original
2016-06-01 14:33:121393browse

跳至

function UTF82JS($str)
{
        $str=iconv("UTF-8","UNICODELITTLE",$str);
        for($i=0;$i<strlen($str);$i+=2){
                $js.=sprintf("%%u%02x%02x",ord($str[$i+1]),ord($str[$i]));
        }
        return $js;
}

function JS2UTF8($str)
{
        for($i=0;$i<strlen($str);$i+=6){
                list($a,$b)=sscanf(substr($str,$i),"%%u%02x%02x");
                $unicode.=chr($b).chr($a);
        }
        return iconv("UNICODELITTLE","UTF-8",$unicode);
}

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn