この関数は、文字の配列をループして特殊文字をチェックし、それらのいずれかが許可された文字のリストと一致しないかどうかをチェックします。この関数の何が問題になっていますか? あなたが助けることができれば、どうもありがとうございました!
str_split_array($stringPassed); と仮定します。完全に機能します(99%確実に機能するため、他のさまざまな機能で使用しています)
// returns true if a string has special characters
// $stringPassed = input string to split and check
// $checkWhiteSpace = check for whitespace, true or false
function hasSpecialCharacters($stringPassed, $checkWhiteSpace = true) {
// Array of characters ALLOWED
$allowedCharacters = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", 1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
$arrayLen = strlen($stringPassed);
$array = str_split_array($stringPassed);
for($i=0;$i<$arrayLen;$i++) {
if(!in_array($array[$i], $allowedCharacters)) {
return true;
} else if($checkWhiteSpace==true && $array[$i]==" ") {
return true;
}
}
return false;
}
再度、感謝します!