Closed soitif closed 5 hours ago
You need the /u
flag when working with UTF-8 strings.
https://www.php.net/manual/zh/reference.pcre.pattern.modifiers.php
u (PCREUTF8) 这个修饰符打开了 PCRE 的额外功能,这些功能与 Perl 不兼容。模式和主题字符串被视为 UTF-8。 无效的主题字符串会导致 preg* 函数匹配不到任何内容;无效的模式会触发一个 E_WARNING 级别的错误。 五个和六个字节的 UTF-8 序列被视为无效。
$newStr = preg_replace('/[,,;、\s]+/u', ',', $str);
我发送到发顺丰,阿斯蒂芬去玩了,发生,的吴,青峰
Description
The following code:
Resulted in this output:
But I expected this output instead:
PHP Version
PHP 8.3.3
Operating System
Mac