0
我有下面的代码:PHP的preg_replace不工作像预期
<?php
$test = "xxxx..AAA?!";
echo $test."\n";
$test = preg_replace("[^a-zA-Z0-9-]", "", $test);
echo $test."\n";
?>
我想删除不属于字母,数字字符全部或减号
什么是我的错?
我有下面的代码:PHP的preg_replace不工作像预期
<?php
$test = "xxxx..AAA?!";
echo $test."\n";
$test = preg_replace("[^a-zA-Z0-9-]", "", $test);
echo $test."\n";
?>
我想删除不属于字母,数字字符全部或减号
什么是我的错?
分隔符缺少
$test = preg_replace('/[^a-zA-Z0-9-]/', '', $test);
echo $test . "\n";
此外,我建议使用的PHP_EOL
代替"\n"
为换行符。
啊谢谢!!现在工作:) – soupdiver
:D太棒了!不用说 –
注意:如果使用:'$ test = preg_replace('/ [^ a-zA-Z0-9 - ] + /','',$ test);'它会更快,因为它需要做更少的操作 – noob