Bug #75214 [Com]: trim&rtrim function makes some Chinese characters messy

From: Date: Sat, 16 Sep 2017 02:36:59 +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-211183@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: 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 Previous Comments: ------------------------------------------------------------------------ [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 (#211183) next »