1

I tried this package http://pear.php.net/package/Text_LanguageDetect/

It's pretty accurate on PHP 5.4. But I failed on PHP 7. Any idea why?

Script I run:

<?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));
  }

Input:

This is English. What does this mean?

Same script on PHP 7.0.9

This is English. What does this mean?
Array
(
    [hungarian] => 0.20114942528736
    [albanian] => 0.19632183908046
    [danish] => 0.1848275862069
    [french] => 0.17183908045977
)

Same script on PHP. 5.4.34

This is English. What does this mean?
Array
(
    [english] => 0.34965517241379
    [dutch] => 0.24896551724138
    [latin] => 0.23931034482759
    [hungarian] => 0.20114942528736
)
Hao
  • 6,291
  • 9
  • 39
  • 88

1 Answers1

0

I've just released Text_LanguageDetect version 1.0.0 which works fine on PHP 7.1.

It would have been nice if you had reported that bug in the bugtracker.

cweiske
  • 30,033
  • 14
  • 133
  • 194