开发者

how to tell a string is all in english in php or javascript? [closed]

It'开发者_如何学Go;s difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜