note 127650 added to function.mb-detect-encoding
| From: | mta59066 at gmail dot com | Date: | Mon, 19 Sep 2022 07:47:12 +0000 |
| Subject: | note 127650 added to function.mb-detect-encoding | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219596@lists.php.net to get a copy of this message | ||
The documentation is no longer correct for php8.1 and mb_detect_encoding no longer supports order of
encodings. The example outputs given in the documentation are also no longer correct for php8.1.
This is somewhat explained here https://github.com/php/php-src/issues/8279
I understand the previous ambiguity in these functions, but in my option 8.1 should have deprecated
mb_detect_encoding and mb_detect_order and came up with different functions. It now tries to find
the encoding that will use the least amount of space regardless of the order, and I am not sure who
needs that.
Below is an example function that will do what mb_detect_encoding was doing prior to the 8.1 change.
<?php
function mb_detect_enconding_in_order(string $string, array $encodings): string|false
{
foreach($encodings as $enc) {
if (mb_check_encoding($string, $enc)) {
return $enc;
}
}
return false;
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.173 (proxied: 176.240.52.223)
----
Manual Page -- https://php.net/manual/en/function.mb-detect-encoding.php
Edit -- https://main.php.net/note/edit/127650
Del: integrated -- https://main.php.net/note/delete/127650/integrated
Del: useless -- https://main.php.net/note/delete/127650/useless
Del: bad code -- https://main.php.net/note/delete/127650/bad+code
Del: spam -- https://main.php.net/note/delete/127650/spam
Del: non-english -- https://main.php.net/note/delete/127650/non-english
Del: in docs -- https://main.php.net/note/delete/127650/in+docs
Del: other reasons-- https://main.php.net/note/delete/127650
Reject -- https://main.php.net/note/reject/127650
Search -- https://main.php.net/manage/user-notes.php