Detect language from string in PHP

The language can’t be detected from the character type. There are other ways, but they don’t guarantee complete accuracy. The ‘TextLanguageDetect Pear Package’ can be used with decent accuracy. Below is a sample code for the same −


require_once 'Text/LanguageDetect.php';
$l = new Text_LanguageDetect();
$result = $l->detect($text, 4);
if (PEAR::isError($result)) {
   echo $result->getMessage();
} else {


This will produce the following output −

   [german] => 0.407037037037
   [dutch] => 0.288065843621
   [english] => 0.283333333333
   [danish] => 0.234526748971

It is easy to use and has 52 language databases. But the downside is that the Eastern Asian languages can’t be detected using this package.