奇怪的空格字符- utf8 PHP

时间:2021-04-19 10:04:36

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.

我有一个奇怪的白色字符串,白色的空格不是白色的空格。我有一个问题,用regex和str_replace来转换它们。

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

有什么好办法吗?当您将此文本复制到Notepad++时,它也显示为

Ê    

instead of white space.

而不是空白。

What I am trying to achieve is to run this regex

我要实现的是运行这个regex

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

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

但由于这些“白空间”不是白空间,它们也被移除。

1 个解决方案

#1


3  

I think I got it, from PHP site:

我想我是从PHP网站得到的:

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.

没有将字符串减少为空字符串,这是因为“实体”不是ASCII码32(被trim()删除了),但是在默认的ISO 8859-1字符集中,ASCII码160 (0xa0)。

#1


3  

I think I got it, from PHP site:

我想我是从PHP网站得到的:

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.

没有将字符串减少为空字符串,这是因为“实体”不是ASCII码32(被trim()删除了),但是在默认的ISO 8859-1字符集中,ASCII码160 (0xa0)。