$string = 'Hello this is a bunch of numbers: 333 and letters and $pecial [email protected]!*(';
$foo = preg_replace("/[^a-zA-Z0-9\s]/", "", $string);
echo $foo;
以上的回报:如何使用PHP正则表达式压缩空格字符?
Hello this is a bunch of numbers 333 and letters and pecial Characters
我想保留空格但如果那里有一个以上。如何做到这一点?
它应该看起来像:
Hello this is a bunch of numbers 333 and letters and pecial Characters
'pecial' 字?当然看起来'''没有保留。 – Cyclone 2011-03-24 01:13:42
@Cyclone对,它应该只保留字母,数字和单个空格。 – 2011-03-24 01:15:01