Req #75214 [Opn]: trim&rtrim function makes some Chinese characters messy
| From: | cmb@php.net | Date: | Sat, 16 Sep 2017 13:28:31 +0000 |
| Subject: | Req #75214 [Opn]: trim&rtrim function makes some Chinese characters messy | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-211189@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
Updated by: cmb@php.net
Reported by: yzhsh89 at 126 dot com
Summary: trim&rtrim function makes some Chinese characters
messy
Status: Open
Type: Feature/Change Request
Package: *Unicode Issues
Operating System: ANY
PHP Version: 5.6.31
Block user comment: N
Private report: N
New Comment:
Request #23501 already suggests to add mb_trim(). Shouldn't we
close this ticket as duplicate?
Previous Comments:
------------------------------------------------------------------------
[2017-09-16 03:18:08] yohgaki@php.net
Standard string functions does not support multibyte encodings basically.
You cannot use multibyte chars as trimming char.
------------------------------------------------------------------------
[2017-09-16 02:45:32] Wes dot example at example dot org
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
------------------------------------------------------------------------
[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