php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #54697 trim function not giving right results
Submitted: 2011-05-09 18:37 UTC Modified: 2011-05-09 20:23 UTC
From: narjsifatima at yahoo dot com Assigned: philip (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3SVN-2011-05-09 (snap) OS: WindowsXP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: narjsifatima at yahoo dot com
New email:
PHP Version: OS:

 

 [2011-05-09 18:37 UTC] narjsifatima at yahoo dot com
Description:
------------
I am writing a simple function which is not giving the correct result.

Please somebody check it.

Test script:
---------------
Here is the code.

$hello  = "Hello World";
$trimmed = trim($hello, "HdWr");
echo($trimmed);

Expected result:
----------------
ello ol

Actual result:
--------------
ello Worl

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-09 19:08 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2011-05-09 19:08 UTC] rasmus@php.net
trim, as per the documentation, trims a string "from the beginning and end of a 
string" it doesn't replace characters in the middle of it. You probably want a 
str_replace here.

str_replace(array('H','d','W','r'),'',$hello);
 [2011-05-09 20:22 UTC] philip@php.net
Automatic comment from SVN on behalf of philip
Revision: http://svn.php.net/viewvc/?view=revision&revision=310860
Log: Clarified removing middle strings via an example and note. Deals with PHP Bug #54697
 [2011-05-09 20:23 UTC] philip@php.net
-Status: Bogus +Status: Closed -Type: Bug +Type: Documentation Problem -Package: Strings related +Package: Documentation problem -Assigned To: +Assigned To: philip
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 27 19:00:03 2025 UTC