Search code examples
phpspecial-charactershidden-charactersnon-breaking-characters

PHP: How to get rid of strange characters like "\u00a0"?


I got a messy bunch of JSON data to import into my database (for further purposes). When i checked them out (opened in a Text Editor), they contain so many weird (gibberish) characters like:

  • \u00a0

For example, data.json:

[{"title":"hello world!","html_body":"<p>Hello\u00a0 from the\u00a0  other side.\u00a0 <\/p>"}]

And then, obviously, below code simply WON'T work:

$clean = str_replace("\u00a0", "", $string);

Despite whatever those character are for, how can i get rid of them anyway please?


Solution

  • Thanks for everyone in the comment section, who (at least) helped me to know those are non-breaking characters. I then googled and found a working solution by myself anyhow:

    $clean_html_body = preg_replace('/\xc2\xa0/', '', $html_body);
    

    Thanks again all. :)