Edit report at https://bugs.php.net/bug.php?id=81390&edit=1
ID: 81390
Comment by: alec at alec dot pl
Reported by: alec at alec dot pl
Summary: mb_detect_encoding() regression
Status: Assigned
Type: Bug
Package: mbstring related
PHP Version: 8.1.0beta5
Assigned To: alexdowad
Block user comment: N
Private report: N
New Comment:
That's better, but did you convert it to iso-8859-2 and then try to detect?
Previous Comments:
------------------------------------------------------------------------
[2021-12-05 16:01:08] alexdowad@php.net
Hi, Alec. Please keep up the great work with testing. I tried the text which you linked to:
---------------
$text = "Ola szykuje siÄ do szkoÅy. Jest już w piÄ
tej klasie. Dawniej obawiaÅa
siÄ szkoÅy, teraz bardzo lubi tam chodziÄ. W szkole nie tylko uczy siÄ ciekawych rzeczy
â spotyka też swoich kolegów i koleżanki. Najbardziej lubi spÄdzaÄ czas ze
swoimi przyjacióÅmi z klasy â sÄ
to Monika i MichaÅ.
Ola lubi wszystkie przedmioty. Wie, że nauka jest ważna. Najmilej spÄdza czas na lekcjach o
przyrodzie â Ola bardzo lubi zwierzÄta. W klasie Oli mieszka chomik. Wszystkie dzieci
dbajÄ
o niego. PrzynoszÄ
mu jedzenie i gÅaszczÄ
. Ola nie ma wÅasnego zwierzÄcia,
wiÄc chomik to kolejny powód dla którego lubi chodziÄ do szkoÅy.
SzkoÅa Oli jest blisko jej domu. Ola chodzi do szkoÅy sama. Gdy Ola byÅa mÅodsza â
zawsze odprowadzaÅ jÄ
tam tata, mama lub babcia. Przed każdym dniem szkoÅy Ola pakuje
plecak. Sprawdza czy sÄ
wszystkie ksiÄ
żki i zeszyty. Sprawdza też piórnik â czy
jest tam linijka, dÅugopis, oÅówek, gumka i mazaki.
W przerwie miÄdzy lekcjami Ola je w szkole obiad. DziÄki temu ma dużo siÅy na dalszÄ
naukÄ. Po szkole droga do domu jest krótka, ale zajmuje Oli dużo czasu. Dlaczego? Bo to
czas, w którym lubi rozmawiaÄ z koleżankami i kolegami podczas spaceru do domu. Ola jednak
wie, że nie może wróciÄ późno.";
echo mb_detect_encoding($text,'utf-8,windows-1252,iso-8859-1,iso-8859-2', true),
"\n";
-------------
And then, in my shell:
-----------------
17:56 ~prog/php/php-src % ./sapi/cli/php test.php
UTF-8
-----------------
Looks good to me! That's on the tip of my development branch, which (crucially) does include
the latest patch for Polish... the one which you said you didn't use.
Please do your best to see if you can still find breakage anywhere! If you find anything else which
is arguably a bug, I will be very, very happy to fix it!
------------------------------------------------------------------------
[2021-11-30 12:28:24] cmb@php.net
Related To: Bug #81676
------------------------------------------------------------------------
[2021-11-28 10:38:30] alec at alec dot pl
I've another case which is either a bug or an indication that the method can't really
distinguish utf-8 from iso-8859-*/windows-125X charsets. I'm not sure it's only a Polish
thing, but most likely not.
I took a sample text from https://lingua.com/pl/polski/czytanie/czas-do-szkoly/
and used it with
mb_detect_encoding($text,'utf-8,windows-1252,iso-8859-1,iso-8859-2', true);
It returns windows-1252, but it should be utf-8. If I convert the text to iso-8859-2, it still
returns windows-1252.
ps. I didn't use your latest patch for Polish.
------------------------------------------------------------------------
[2021-11-25 08:42:10] alexdowad@php.net
Thanks, Alec.
Hopefully this will be merged soon:
https://github.com/php/php-src/pull/7659/commits/889d2fe3bafdb8e9da39b2297d6e9f13a518584e
------------------------------------------------------------------------
[2021-11-25 06:32:31] alec at alec dot pl
Well, let's take Polish language (which is ISO-8859-2 family) as an example. The one I know.
There's a table https://pl.wikipedia.org/wiki/Alfabet_polski#Cz%C4%99sto%C5%9B%C4%87_wyst%C4%99powania_liter
(only in Polish version). According to this, some diacritical characters are quite common (~1-2%).
E.g. letter Å is more common that letter B.
I have no idea how that applies to the whole character set detection, though.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=81390
--
Edit this bug report at https://bugs.php.net/bug.php?id=81390&edit=1