how to tell a string is all in english in php or javascript? [closed]
how to tell a string is all in english of php. eg:$test="eeeeeeeeeeeee"
how to tell that the $test
string is writen all in english.
If you have all the characters you consider "english" into a string, then it can be done like this:
$english_chars = 'abcdefghijklmnopqrstuvwxyz';
$input = 'eeeeeee';
$is_all_english = strspn($input, $english_chars) == strlen($input);
Google Translate API is probably your best bet for reliably detecting the language of a string:
http://code.google.com/apis/language/translate/v1/getting_started.html#usingDetect
精彩评论