Doc #74528 [Opn->Nab]: mb_check_encoding Documentation Confusing
| From: | cmb@php.net | Date: | Tue, 02 May 2017 14:33:40 +0000 |
| Subject: | Doc #74528 [Opn->Nab]: mb_check_encoding Documentation Confusing | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-14668@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74528&edit=1
ID: 74528
Updated by: cmb@php.net
Reported by: james dot antrim at nm dot thm dot de
Summary: mb_check_encoding Documentation Confusing
-Status: Open
+Status: Not a bug
Type: Documentation Problem
-Package: Documentation problem
+Package: mbstring related
Operating System: Debian 3.16.39-1+deb8u2 (2017-03
PHP Version: 5.6.30
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
mb_detect_encoding() is not supposed to do any conversion, so the
documentation is correct in this regard. However, if you want to
check for 'UTF-8' (and maybe other encodings as well), you have
to use strict detection, see <https://3v4l.org/DFIAs> vs.
<https://3v4l.org/M23D4> and also
<http://php.net/manual/en/function.mb-detect-encoding.php#102510>.
Previous Comments:
------------------------------------------------------------------------
[2017-05-02 10:08:21] james dot antrim at nm dot thm dot de
Description:
------------
---
From manual page: http://www.php.net/function.mb-detect-encoding
---
I saved a file that was originally ISO-8859-1 to several different coding standards, among them
UTF-8 and Japanese Shift JIS. When using this function with 'UTF-8' as the 'encoding
list' parameter I always get 'UTF-8' as the return value.
I assume this is working as intended, because it really solves both the problem of detection and
conversion in one function. I find the return documentation more than confusing, because, despite
the function being called 'detect' it does not tell me the original string's
encoding, but the encoding of the converted string if conversion was possible. My suggestion would
be:
"The character encoding or FALSE if the encoding cannot be converted to any of the given
strings."
Test script:
---------------
Convert any ISO-8859-1 file to any other encoding, then run mb_detect_encoding($file,
'UTF-8', true) on it.
This same documentation problem is evident for mb_check_encoding($file, 'UTF-8') which
will always return true under the same conditions.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74528&edit=1