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:
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?
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. :)
If you have individual strings that might have non-breaking spaces or line returns at the end of them, you can trim these when putting together your JSON data by using this:
$dat = trim($dat," \\t\\n\\r\\0\\x0B\\xc2\\xa0");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.