Bug->Req #75214 [Opn]: trim&rtrim function makes some Chinese characters messy

From: Date: Sat, 16 Sep 2017 03:18:10 +0000
Subject: Bug->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-211185@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: yohgaki@php.net Reported by: yzhsh89 at 126 dot com Summary: trim&rtrim function makes some Chinese characters messy Status: Open -Type: Bug +Type: Feature/Change Request Package: *Unicode Issues Operating System: ANY PHP Version: 5.6.31 Block user comment: N Private report: N New Comment: Standard string functions does not support multibyte encodings basically. You cannot use multibyte chars as trimming char. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#211185) next »