奇怪的空格字符-utf8 PHP [英] weird white space characters - utf8 PHP
问题描述
我在字符串中有一个奇怪的空格,空格不是空格.我在使用regex和str_replace进行转换时遇到问题.
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);
任何想法如何解决? utf8_encode也不起作用,正则表达式也不能,当您将此文本复制到Notepad ++时,它显示为
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
Ê
代替空格.
我想要实现的是运行此正则表达式
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.
推荐答案
我想我是从PHP网站获得的:
I think I got it, from PHP site:
您可能想知道为什么
trim(html_entity_decode(' '));
不会将字符串缩减为空字符串,这是因为' '实体不是默认ISO 8859-1字符集中的ASCII代码32(由trim()剥离),而是ASCII代码160(0xa0).
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.
这篇关于奇怪的空格字符-utf8 PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!