可能重複:
Function to return only alpha-numeric characters from string?PHP字符串僅控制
從$string = "hey hello 9times-%&";
開始,我想更換所有不數字的字符[0 -9]或[az,AZ]類型。
是否有一個很好的方法來顯示這個過程控制?
EDITED
我忘了,我需要留空白欄空白,我的意思是:
「哎&/K」必須返回如「嗨K」和不作爲「heyk」
可能重複:
Function to return only alpha-numeric characters from string?PHP字符串僅控制
從$string = "hey hello 9times-%&";
開始,我想更換所有不數字的字符[0 -9]或[az,AZ]類型。
是否有一個很好的方法來顯示這個過程控制?
EDITED
我忘了,我需要留空白欄空白,我的意思是:
「哎&/K」必須返回如「嗨K」和不作爲「heyk」
<?php
$string = "hey hello 9times-%&";
$string = preg_replace('/[^0-9A-Z\s]+/i', '', $string);
echo $string;
?>
我編輯的問題 – sbaaaang
我已經更新了我的答案。 –
什麼preg_replace
:
$clean = preg_replace('/[^0-9a-z\s]/i','',$input);
preg_replace('/[^ \w]+/i', '', $string);
這也會起作用。請參閱codepad example。
用什麼取代它們? – hjpotter92
用什麼都替換它們,只留下所有原始字符串的空格 – sbaaaang
@GiantofaLannister對不起,我必須使用刪除不替換術語 – sbaaaang