将所有\ u符号转换为UTF8

时间:2015-01-03 23:40:57

标签: php regex

我的测试代码示例:

<?
$city = "L\u00e9ry, Quebec";
echo 'city original: '.$city.'<br>';
$city = preg_replace('/u([\da-fA-F]{4})/', '&#x\1;', $city);
echo 'city modified: '.$city.'<br>';
?>

我的结果是:

city original: L\u00e9ry, Quebec
city modified: L\éry, Q

我有一些问题... thx

1 个答案:

答案 0 :(得分:-3)

这应该适合你:

$city = preg_replace('/\\\\u([0-9a-fA-F]{4})/', '&#x\1;', $city);

输出:

city original: L\u00e9ry, Quebec
city modified: Léry, Quebec