tags:

views:

58

answers:

2

What is the best way for check the input, if it contains any character from other languages. (except english ) Thanks in advance

A: 
$input = 'abcабв';
$out = array();
preg_match_all(
    "|[a-zA-Z]?|",
    $input,
    $out
);

$out is going to contain all non-latin characters(абв).

kgb
and what about special chars like `.`, `()`, `[]` or so much more that can be in a string without making it a string in foreign language?
jigfox
yep, you are right, that would only work for single words..
kgb
+2  A: 
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.

Ascii Table source

jigfox