我试过这个包http://pear.php.net/package/Text_LanguageDetect/
在PHP 5.4上非常准确。但我在PHP 7上失败了。知道为什么吗?
我运行的脚本:
<?php
require_once 'Text/LanguageDetect.php';
$l = new Text_LanguageDetect;
$stdin = fopen('php://stdin', 'r');
echo "Supported languages:\n";
try {
$langs = $l->getLanguages();
} catch (Text_LanguageDetect_Exception $e) {
die($e->getMessage());
}
sort($langs);
echo join(', ', $langs);
//$l->setNameMode(2);
while ($line = fgets($stdin)) {
print_r($l->detect($line, 4));
//print_r($l->detectSimple($line));
}
输入:
This is English. What does this mean?
PHP 7.0.9上的相同脚本
This is English. What does this mean?
Array
(
[hungarian] => 0.20114942528736
[albanian] => 0.19632183908046
[danish] => 0.1848275862069
[french] => 0.17183908045977
)
PHP上的相同脚本。 5.4.34
This is English. What does this mean?
Array
(
[english] => 0.34965517241379
[dutch] => 0.24896551724138
[latin] => 0.23931034482759
[hungarian] => 0.20114942528736
)
答案 0 :(得分:0)
我刚刚发布了Text_LanguageDetect version 1.0.0,它在PHP 7.1上运行良好。
如果您在bugtracker中报告了该错误,那就太好了。