PHP remove Non-Alphanumeric Characters – PHP 如何移除非英數字符

在PHP上 如何移除非英數字符
我們可以使用Regular Expression 來解決這個問題

<strong>[^A-Za-z0-9 ]</strong>

這個Regular Expression的規則是用來選擇出非英文數字和空格的字串找出來.之後用Empty String來取代

E.G.

$input = "How Are you? 你好嗎? ShareChiWai";

echo "Original Input:";
echo "<br/>";
echo $input;
echo "<br/>";

echo "Removed Non-Alphanumeric Characters Input:";
echo "<br/>";
"/[^A-Za-z0-9 ]/", '', $input);

Demo:
http://sharechiwai.com/phpdemo/non_alphanumeric_chars_filter

PHP Remove Non Alphanumberic Characters
Hope you find it useful

Leave a Reply