I need to clean a string that comes (copy/pasted) from various Microsoft Office suite applications (Excel, Access, and Word), each with its own set of encoding.
I\'m
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 );
A minor point: \u00a0 is actually a non-breaking space character, c.f. http://www.fileformat.info/info/unicode/char/a0/index.htm
So it might be more correct to replace it with " "
This did the trick for me:
$str = preg_replace( "~\x{00a0}~siu", " ", $str );
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.
Try this:
$str = str_replace("\u{00a0}", ' ', $str);