4

I have some strange characters showing up in a production database. The string I want to replace is \u00fc\u00be\u008c\u00a3\u00a4\u00bc.

This fails.

$column = str_replace('\u00fc\u00be\u008c\u00a3\u00a4\u00bc', "'", $column);

and this works.

$column = str_replace('ü¾£¤¼',"'",$column) ;

What is the best way to replace unicode characters in a PHP string without copying in the decoded text?

Keith John Hutchison
  • 4,582
  • 8
  • 40
  • 60
  • this is just a guess, since I have nowhere to test this atm, but try using double quotes within your first example. Single quotes just treat that as literal text. – Auris Nov 25 '16 at 11:05
  • 2
    You should look at the answers on http://stackoverflow.com/questions/6058394/unicode-character-in-php-string [Edit: The question deals with a single character, but the same principles apply to a string of them.] – EPB Nov 25 '16 at 11:34
  • Thanks @EPB. using json_decode() worked. – Keith John Hutchison Nov 25 '16 at 21:15

1 Answers1

6

After following the lead from https://stackoverflow.com/users/395384/epb I used json_decode to translate the unicode which works.

$unicode = json_decode("\u00fc\u00be\u008c\u00a3\u00a4\u00bc") ;
$column = str_replace($unicode, "'", urldecode($row[$columnIndex]));
Community
  • 1
  • 1
Keith John Hutchison
  • 4,582
  • 8
  • 40
  • 60