例
<?php
require_once 'Text/LanguageDetect.php';
$l = new Text_LanguageDetect();
echo "サポートしている言語:\n";
$langs = $l->getLanguages();
if (PEAR::isError($langs)) {
die($langs->getMessage());
}
sort($langs);
echo implode(', ', $langs) . "\n\n";
$text = <<<EOD
Hallo! Das ist ein Text in deutscher Sprache.
Mal sehen, ob die Klasse erkennt, welche Sprache das hier ist.
EOD;
$result = $l->detect($text, 4);
if (PEAR::isError($result)) {
echo $result->getMessage(), "\n";
} else {
print_r($result);
}
?>
上の例の結果は、次のようになります。
サポートしている言語:
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
(
[german] => 0.407037037037
[dutch] => 0.288065843621
[english] => 0.283333333333
[danish] => 0.234526748971
)