4 PHP library to identify human languages from text samples.
5 Returns confidence scores for each.
15 $ pear install Text_LanguageDetect
21 $ composer require pear/text_languagedetect
26 Also see the examples in the ``docs/`` directory and
27 the `official documentation`__.
29 __ http://pear.php.net/package/Text_LanguageDetect/docs
33 Simple language detection::
36 require_once 'Text/LanguageDetect.php';
38 $text = 'Was wäre, wenn ich Ihnen das jetzt sagen würde?';
40 $ld = new Text_LanguageDetect();
41 $language = $ld->detectSimple($text);
46 Show the three most probable languages with their confidence score::
49 require_once 'Text/LanguageDetect.php';
51 $text = 'Was wäre, wenn ich Ihnen das jetzt sagen würde?';
53 $ld = new Text_LanguageDetect();
54 //3 most probable languages
55 $results = $ld->detect($text, 3);
57 foreach ($results as $language => $confidence) {
58 echo $language . ': ' . number_format($confidence, 2) . "\n";
70 Instead of returning the full language name, ISO 639-2 two and three
71 letter codes can be returned::
74 require_once 'Text/LanguageDetect.php';
75 $ld = new Text_LanguageDetect();
77 //will output the ISO 639-1 two-letter language code
80 echo $ld->detectSimple('Das ist ein kleiner Text') . "\n";
82 //will output the ISO 639-2 three-letter language code
85 echo $ld->detectSimple('Das ist ein kleiner Text') . "\n";
148 http://pear.php.net/package/Text_LanguageDetect
150 http://pear.php.net/bugs/search.php?cmd=display&package_name[]=Text_LanguageDetect
152 http://pear.php.net/package/Text_LanguageDetect/docs
154 https://travis-ci.org/pear/Text_LanguageDetect
156 .. image:: https://travis-ci.org/pear/Text_LanguageDetect.svg?branch=master
157 :target: https://travis-ci.org/pear/Text_LanguageDetect