替换字符串中除字母和空格之外的所有内容
Replace everything in string except letters and spaces
我正在尝试替换字符串中除字母和空格之外的所有内容。我该怎么做?
$str = "one two three !@#$%^&*()_+|";
$str = preg_replace('/\PL/u', '', $str);
echo $str;
结果:
onetwothree
想要的结果:
one two three
$str = preg_replace('/[^\p{L} ]+/u', '', $str);
想法是替换非(^
)字母(\p{L}
)或空格的倍数(+
)。
我正在尝试替换字符串中除字母和空格之外的所有内容。我该怎么做?
$str = "one two three !@#$%^&*()_+|";
$str = preg_replace('/\PL/u', '', $str);
echo $str;
结果:
onetwothree
想要的结果:
one two three
$str = preg_replace('/[^\p{L} ]+/u', '', $str);
想法是替换非(^
)字母(\p{L}
)或空格的倍数(+
)。