2012-08-15 90 views
0

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

我能做些什麼來解決它?

在此先感謝

+2

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

回答

5

你忘了空間

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

如:

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