-1

I have one string:

"Hello\u00c2\u00a0World"

I would like convert in:

"Hello World"

I try :

str_replace("\u00c2\u00a0"," ","Hello\u00c2\u00a0World");

or

str_replace("\\u00c2\\u00a0"," ","Hello\u00c2\u00a0World");

but not work!

Mauro Midolo
  • 1,841
  • 3
  • 14
  • 34

5 Answers5

1

Resolve!

str_replace(chr(194).chr(160)," ","Hello\u00c2\u00a0World");
Mauro Midolo
  • 1,841
  • 3
  • 14
  • 34
0

If you would like to remove \u.... like patterns then you can use this for example:

$string = preg_replace('/(\\\u....)+/',' ',$input);
Lajos Veres
  • 13,595
  • 7
  • 43
  • 56
  • i don't want remove but replace! – Mauro Midolo Nov 12 '13 at 15:00
  • This replaces it to spaces. If you would like to unescape them, this link (mentioned by perdeu) can help: http://stackoverflow.com/questions/8180920/how-to-decode-something-beginning-with-u-with-php – Lajos Veres Nov 12 '13 at 15:02
0

You are most of the way there.

$stuff = "Hello\u00c2\u00a0World";
$newstuff = str_replace("\u00c2\u00a0"," ",$stuff);

you need to put the return from str_replace into a variable in order to do something with it later.

Jonnyboy
  • 11
  • 1
0

This should work

$str="Hello\u00c2\u00a0World";   
echo str_replace("\u00c2\u00a0"," ",$str);
0

You may try this, taken from this answer

function replaceUnicode($str) {
    return preg_replace_callback("/\\\\u00([0-9a-f]{2})/", function($m){ return chr(hexdec($m[1])); }, $str);
}
echo replaceUnicode("Hello\u00c2\u00a0World");
Community
  • 1
  • 1
The Alpha
  • 143,660
  • 29
  • 287
  • 307