PHP ereg_replace允许空格

问题描述:

使用preg_replace我想只允许字母数字和空格, 但ereg_replace("[^A-Za-z0-9\w\]删除所有空格。PHP ereg_replace允许空格

我能做些什么来解决它?

在此先感谢

+2

对阵'[\ W \ S]'匹配非字母,非空格字符。 – 2012-08-15 16:59:07

你忘了空间

[^A-Za-z0-9\w\ ] 
______________^ 

如:

$returnValue = preg_replace('@[^A-Za-z0-9\w\ ]@', '', 'I forgot a %space!!!'); 
// I forgot a space