function unicode_decode($name){
$pattern = '/([\w]+)|(\\\u([\w]{4}))/i';
preg_match_all($pattern, $name, $matches);
if (!empty($matches)){
$name = '';
for ($j = 0; $j < count($matches[0]); $j++){
$str = $matches[0][$j];
if (strpos($str, '\\u') === 0){
$code = base_convert(substr($str, 2, 2), 16, 10);
$code2 = base_convert(substr($str, 4), 16, 10);
$c = chr($code).chr($code2);
$c = iconv('ucs-2', 'utf-8', $c);
$name .= $c;
}
else{
$name .= $str;
}
}
}
return $name;
}
转码:json_encode('芝麻笔记51card.wang')
解码:
$str1 = '\u829d\u9ebb\u7b14\u8bb051card.wang';
echo '<p>'.unicode_decode($str1).'</p>';