2019年10月16日 星期三

unicode and utf8

https://pjchender.blogspot.com/2018/06/guide-unicode-javascript.html


PHP to character


print_r(json_decode('{"t":"\u00ed"}'));

$str = "\u9060\u50b3\u96fb\u4fe1";
echo unicode2utf8($str);

function unicode2utf8($str){
        if(!$str) return $str;
       
        $decode = json_decode($str);
        if($decode) return $decode;

        $str = '["' . $str . '"]';
        $decode = json_decode($str);
        if(count($decode) == 1){
                return $decode[0];
        }
        return $str;
}


ref  1

沒有留言:

張貼留言