php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35584 ltrim() chops the first letter "C"
Submitted: 2005-12-07 15:38 UTC Modified: 2005-12-07 21:09 UTC
From: motion_4u at hotmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.1.1 OS: Win2k Server
Private report: No CVE-ID: None
 [2005-12-07 15:38 UTC] motion_4u at hotmail dot com
Description:
------------
Function ltrim() chops one character extra incase the string starts with "c"!

funny but true
You better check the rtrim() function too since I have found bugs there too.

You can test this function directly online there:

http://motions.sytes.net/funny_ltrim.php

Reproduce code:
---------------
$url="C:\\dir1\\dir2\\filename.txt"; 
echo "<br>";
$url =  ltrim(strrchr($url,'\x5c'),'\x5c'); 
echo $url;

// ok output: filename.txt

$url="C:\\dir1\\dir2\\cfilename.txt"; 
echo "<br>";
$url =  ltrim(strrchr($url,'\x5c'),'\x5c'); 
echo $url;

// output: again filename.txt but should be cfilename.txt 
// WHERE IS THE "C" CHARACTER?



Expected result:
----------------
filename.txt


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-07 15:51 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

See http://php.net/strrchr and http://php.net/ltrim
 [2005-12-07 21:05 UTC] motion_4u at hotmail dot com
I agree, the problem is not the PHP, though those they program it. There is no logical explanation for that the function ltream() should respond like that and if so, it is useless and should be removed.
The documentations about this function do not refer to this problem too.
What interesting about this problem is that the Borland Dos Compiler version 4.0 had the same problem.
 [2005-12-07 21:09 UTC] tony2001@php.net
Read the docs AGAIN and see that you're explicitly trimming symbols '\', 'x', '5' and 'c'.
No bug or something unexpected here, move along.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 08:01:35 2024 UTC