Php 什么是所有类型的空白区变体?
我想用下划线替换所有类型的空格 但我的问题是有很多种空白。 目前发现的是:Php 什么是所有类型的空白区变体?,php,regex,unicode,removing-whitespace,Php,Regex,Unicode,Removing Whitespace,我想用下划线替换所有类型的空格 但我的问题是有很多种空白。 目前发现的是: 不间断空间 太空 电磁空间 薄空间 我正在使用 preg_replace("/\p{Z}/", "_", $text); 我想要所有类型的空白的列表。您可以使用 preg_replace("/\s/u", "_", $text); u修饰符将使\s识别Unicode,并将匹配任何Unicode空白字符 这里是对U+0020U+00A0U+1680U+2000U+2001U+2002U+2003U+2004U+2005
preg_replace("/\p{Z}/", "_", $text);
我想要所有类型的空白的列表。您可以使用
preg_replace("/\s/u", "_", $text);
u
修饰符将使\s
识别Unicode,并将匹配任何Unicode空白字符
这里是对U+0020U+00A0U+1680U+2000U+2001U+2002U+2003U+2004U+2005U+2006U+2007U+2008U+2009U+200AU+202FU+205FU+3000U+2028U+2029TextU+000B\r\n\t
string:
$text = "
Text\x0B\r\n\t";
$res = preg_replace("/\s/u", "_", $text);
echo $res; // => ___________________Text____
见
你可以用
preg_replace("/\s/u", "_", $text);
u
修饰符将使\s
识别Unicode,并将匹配任何Unicode空白字符
这里是对U+0020U+00A0U+1680U+2000U+2001U+2002U+2003U+2004U+2005U+2006U+2007U+2008U+2009U+200AU+202FU+205FU+3000U+2028U+2029TextU+000B\r\n\t
string:
$text = "
Text\x0B\r\n\t";
$res = preg_replace("/\s/u", "_", $text);
echo $res; // => ___________________Text____
见
谢谢,@Wiktor Stribiżew快速准确的回答!谢谢,@Wiktor Stribiżew快速准确的回答!