我用preg_match
允許字母和數字輸入,刪除任何不是字母或數字的字母?
if(!preg_match('/^[a-zA-Z0-9]+$/', $file_rename))
{
$error = true;
echo '<error elementid="file_rename" message="FILE - please use alphabets and numbers only" />';
}
如果我想刪除任何英文字母不是一個字母或數字?
例如,
test_1
到
test 1
,或者
test&2
到
test 2
而不是「刪除」,你的意思是「用空格替換」?怎麼樣多次出現?它們全部被替換爲每個空間還是被壓縮爲單個空間替換? – Phil
對不起,我的意思是「用空格替換」謝謝。所以'test _&_ 1'應該被替換爲'test 1',然後我將用一個空格替換多個空格'preg_replace('/ \ s \ s + /','',$ string)' – laukok
[Regex to match除了字母和數字以外的所有字符](http://stackoverflow.com/questions/2167145/regex-to-match-all-characters-except-letters-and-numbers) – mario