PHP input filtering : Only English alphabet
What is the best way for check the input, if it contains any character from other la开发者_StackOverflow中文版nguages. (except english )
if (preg_match("/[^\x00-\x7F]/",$string)) {
// $string contains at least
} else {
// $string doesn't contain any foreign characters
}
This will check for any character that has ascii code higher than 127, because if it is higher, it's not in the english alphabet. The 7-bit Ascii code contains every english character.
if this
preg_match("/[^\x00-\x7F]/",$string)
doesn't work (you get No ending delimiter '/' found ) then try this
preg_match('/[^\x00-\x7F]/',$string)
$input = 'abcабв';
$out = array();
preg_match_all(
"|[a-zA-Z]?|",
$input,
$out
);
$out is going to contain all non-latin characters(абв).
精彩评论