2010-03-30 202 views

回答

12

我假設你的意思是,a-z而不是a-Z,你的正則表達式內,但您可以使用preg_replace

$new_string = preg_replace("/[^a-zA-Z0-9\s]/", "", $string); 

它採用作爲參數的模式([a-zA-Z0-9]),更換("")和主題( $string)並返回新的字符串($new_string

4
$string = preg_replace('/[^a-zA-Z0-9]/', '', $string); 
3

\W爲的快捷方式。可能不是非常有幫助,因爲它也允許強調,但我想我會讓你知道。