开发者

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.

PHP input filtering : Only English alphabet

source


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(абв).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜