Bug #75214 [Com]: trim&rtrim function makes some Chinese characters messy
| From: | Wes dot example at example dot org | Date: | Sat, 16 Sep 2017 02:45:33 +0000 |
| Subject: | Bug #75214 [Com]: trim&rtrim function makes some Chinese characters messy | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-211184@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75214&edit=1
ID: 75214
Comment by: Wes dot example at example dot org
Reported by: yzhsh89 at 126 dot com
Summary: trim&rtrim function makes some Chinese characters
messy
Status: Open
Type: Bug
Package: *Unicode Issues
Operating System: ANY
PHP Version: 5.6.31
Block user comment: N
Private report: N
New Comment:
here's a list of functions you can and you cannot use with multibyte encodings
http://www.phpwact.org/php/i18n/utf-8?rev=1165702501
Previous Comments:
------------------------------------------------------------------------
[2017-09-16 02:36:55] Wes dot example at example dot org
hi, php strings are generic byte sequences, not character sequences.
which means that you are not allowed to use the second parameter of trim, ltrim and rtrim like that.
look for a trim/ltrim/rtrim function that works on multibyte strings, and look at the functions
bundled in the mbstring, intl or iconv extensions
------------------------------------------------------------------------
[2017-09-16 01:39:29] yzhsh89 at 126 dot com
Description:
------------
Some Chinese characters may lead to messy codes through trim or rtrim, such as the Chinese character
"è¨", and other untested.
I am using the PHP5.6.30 version, Other versions have not been tested.
Test script:
---------------
$str = "ãæ±è¯è¨ã";
echo ltrim($str, 'ã')."<br/>"; //correct
echo rtrim($str, 'ã')."<br/>"; //messy
echo trim($str, 'ã')."<br/>"; //messy
Expected result:
----------------
æ±è¯è¨ã
ãæ±è¯è¨
æ±è¯è¨
Actual result:
--------------
æ±è¯è¨ã
ãæ±è¯ï¿½
æ±è¯ï¿½
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75214&edit=1