开发者

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

开发者 https://www.devze.com 2023-02-24 16:43 出处:网络
It'开发者_如何学Go;s difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
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

精彩评论

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

关注公众号