I have a string with "\u00a0", and I need to replace it with "" str_replace fails

By combining ord() with substr() on my string containing \u00a0, I found the following curse to work:

$text = str_replace( chr( 194 ) . chr( 160 ), ' ', $text );

Works for me, when I copy/paste your code. Try replacing the double quotes in your str_replace() with single quotes, or escaping the backslash ("\\u00a0").


I just had the same problem. Apparently PHP's json_encode will return null for any string with a 'non-breaking space' in it.

The Solution is to replace this with a regular space:

str_replace(chr(160),' ');

I hope this helps somebody - it took me an hour to figure out.