1

我试过这个包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
)
4

1 回答 1

0

我刚刚发布了Text_LanguageDetect 1.0.0 版,它在 PHP 7.1 上运行良好。

如果您在 bugtracker 中报告了该错误,那就太好了。

于 2017-03-02T16:59:00.127 回答