weird white space characters - utf8 PHP

2019-02-19 19:26发布

I have a weird whitespaces in string, white spaces are not white spaces. I have a problem with converting them with regex and str_replace i.e.

echo str_replace(' ','_',$string);

any ideas how to fix it? utf8_encode is also not working, regex \s either, when you copy this text to Notepad++ it shows as

Ê    

instead of white space.

What I am trying to achieve is to run this regex

preg_replace('/[^a-z0-9 ]/i','',$string) 

but since those 'whitespaces' are not a whitespaces they are being removed as well.

1条回答
霸刀☆藐视天下
2楼-- · 2019-02-19 19:58

I think I got it, from PHP site:

You might wonder why

trim(html_entity_decode(' '));    

doesn't reduce the string to an empty string, that's because the ' ' entity is not ASCII code 32 (which is stripped by trim()) but ASCII code 160 (0xa0) in the default ISO 8859-1 characterset.

查看更多
登录 后发表回答