0

example of my test code:

<?
$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>';
?>

my result is:

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

I'm having some issues... thx

user3011784
  • 833
  • 1
  • 8
  • 30
  • Aren't there some mb_* functions in the php multibyte string libraries that handle encoding conversions better than manual regex would? I'm just suggesting, I don't really know for sure – Kevin Jan 03 '15 at 23:45
  • Just... put the backslash in your match... `\\\\`, since you're in regex. – Niet the Dark Absol Jan 03 '15 at 23:45

1 Answers1

-3

This should work for you:

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

Output:

city original: L\u00e9ry, Quebec
city modified: Léry, Quebec
Rizier123
  • 58,877
  • 16
  • 101
  • 156
  • Note that this does not replace the sequence with *UTF-8*, rather it turns it into an HTML entity which will only render correctly in an HTML context. The actual data will still be "Léry". – deceze Jan 04 '15 at 03:53
  • @deceze Op wanted to replace it with: `\1` also this is why down Vote? – Rizier123 Jan 04 '15 at 07:43