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
2010-06-25 13:17:53
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
2010-06-25 13:21:17
yep, you are right, that would only work for single words..
kgb
2010-06-25 13:23:52
+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.
jigfox
2010-06-25 13:19:58