-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!

3
  • Where does that string come from? Is it possibly a JSON encoded string? I'm smelling some serious encoding conversion problem here. Commented Nov 12, 2013 at 14:58
  • Remember that you have to assign that back to the string, i.e. $string = str_replace(..); - working: codepad.org/qcCtedUr Commented Nov 12, 2013 at 14:59
  • Check this. Commented Nov 12, 2013 at 15:01

5 Answers 5

1

Resolve!

str_replace(chr(194).chr(160)," ","Hello\u00c2\u00a0World");
Sign up to request clarification or add additional context in comments.

Comments

0

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

$string = preg_replace('/(\\\u....)+/',' ',$input);

2 Comments

i don't want remove but replace!
This replaces it to spaces. If you would like to unescape them, this link (mentioned by perdeu) can help: stackoverflow.com/questions/8180920/…
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.

Comments

0

This should work

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

Comments

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");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.