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

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

PHP中文网
Release: 2016-06-01 14:33:12
Original
1392 people have browsed it

跳至

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);
}
Copy after login

                   

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template