我在删除数字和特殊字符时遇到一些问题。我想从输入中删除所有数字和特殊字符。下面是我的代码:
$input = $_POST["input"];
function preprocessing($input){
$input = trim(strtolower($input));
$remove = '/[^a-zA-Z0-9]/s';
$result = preg_split($remove, $input, -1, PREG_SPLIT_NO_EMPTY);
for($i = 0; $i < count($resultl); $i++){
$result[$i] = trim($result[$i]);
}
return $result;
}
字符串示例:qwd qwd qwdqd123 13#$%^&*) ADDA ''''
输出:数组([0]=> qwd [1] => qwd [2] => qwdqd123[3] => 13[4] =>加入)
数字仍然出现在我的字符串上。如何解决这个问题?
检查
function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
return preg_replace('/[^A-Za-z'-]/', '', $string); // Removes special chars.
}