Example

<?php
require_once 'Text/LanguageDetect.php';
$l = new Text_LanguageDetect();

echo 
"Supported languages:\n";
try {
    
$langs $l->getLanguages();
    
sort($langs);
    echo 
implode(', '$langs) . "\n\n";
} catch (
Text_LanguageDetect_Exception $e) {
    die(
$e->getMessage());
}

$text = <<<EOD
Hallo! Das ist ein Text in deutscher Sprache.
Mal sehen, ob die Klasse erkennt, welche Sprache das hier ist.
EOD;

try {
    
//return 2-letter language codes only
    
$l->setNameMode(2);

    
$result $l->detect($text4);
    
print_r($result);
} catch (
Text_LanguageDetect_Exception $e) {
    die(
$e->getMessage());
}
?>

The above example would give the following output:

Output

Supported languages:
albanian, arabic, azeri, bengali, bulgarian, cebuano, croatian, czech,
danish, dutch, english, estonian, farsi, finnish, french, german, hausa,
hawaiian, hindi, hungarian, icelandic, indonesian, italian, kazakh, kyrgyz,
latin, latvian, lithuanian, macedonian, mongolian, nepali, norwegian, pashto,
pidgin, polish, portuguese, romanian, russian, serbian, slovak, slovene, somali,
spanish, swahili, swedish, tagalog, turkish, ukrainian, urdu, uzbek, vietnamese,
welsh

Array
(
    [de] => 0.40703703703704
    [nl] => 0.2880658436214
    [en] => 0.28333333333333
    [da] => 0.23452674897119
)

   
Language names (Previous) Text_Password (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.