|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75214 trim&rtrim function makes some Chinese characters messy
Submitted: 2017-09-16 01:39 UTC Modified: 2017-09-17 23:11 UTC
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: yzhsh89 at 126 dot com Assigned:
Status: Duplicate Package: *Unicode Issues
PHP Version: 5.6.31 OS: ANY
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: yzhsh89 at 126 dot com
New email:
PHP Version: OS:


 [2017-09-16 01:39 UTC] yzhsh89 at 126 dot com
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:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-16 02:36 UTC] 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 02:45 UTC] Wes dot example at example dot org
here's a list of functions you can and you cannot use with multibyte encodings
 [2017-09-16 03:18 UTC]
-Type: Bug +Type: Feature/Change Request
 [2017-09-16 03:18 UTC]
Standard string functions does not support multibyte encodings basically.
You cannot use multibyte chars as trimming char.
 [2017-09-16 13:28 UTC]
Request #23501 already suggests to add mb_trim(). Shouldn't we
close this ticket as duplicate?
 [2017-09-17 23:11 UTC]
-Status: Open +Status: Duplicate
 [2017-09-17 23:11 UTC]
I agree. Make this a dup of Request #23501
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Dec 03 01:05:56 2022 UTC