删除除空格以外的所有字母数字字符?

时间:2013-01-07 18:49:54

标签: php regex

  

可能重复:
  Regular expression to remove anything but alphanumeric & spaces (in PHP)

我想要

//before preg_replace -> Hi (Jimmy),

$string = preg_replace('/[^\da-z]/i', '', $string);

//after current preg_replace -> HiJimmy
//what it should be -> Hi Jimmy

preg_replace删除除空格外的所有字母数字字符。这可能吗?

1 个答案:

答案 0 :(得分:7)

只需为您的论坛添加空间:

$string = preg_replace('/[^\da-z ]/i', '', $string);
//                              ^ Notice the space here