In PHP, is there a way to detect the language of a string? Suppose the string is in UTF-8 format.
You can see how to detect language for a string in php using the Text_LanguageDetect Pear Package or downloading to use it separately like a regular php library.
I've used the Text_LanguageDetect pear package with some reasonable results. It's dead simple to use, and it has a modest 52 language database. The downside is no detection of Eastern Asian languages.
require_once 'Text/LanguageDetect.php'; $l = new Text_LanguageDetect(); $result = $l->detect($text, 4); if (PEAR::isError($result)) { echo $result->getMessage(); } else { print_r($result); }
results in:
Array ( [german] => 0.407037037037 [dutch] => 0.288065843621 [english] => 0.283333333333 [danish] => 0.234526748971 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With