php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43431 Using /H in haystack causes truncated results
Submitted: 2007-11-27 18:51 UTC Modified: 2007-12-19 17:34 UTC
From: lowell at ietech dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.2.5 OS: Linux data 2.6.18.2-34
Private report: No CVE-ID: None
 [2007-11-27 18:51 UTC] lowell at ietech dot com
Description:
------------
Using '/H' (uppercase 'H' is relevant) near the end of the haystack truncates the result (In example below, first 5 letters of 'Health').  Have tried many strings to determine consistency, but have failed.  Using '/home' instead of '/Home' in string produced a different result, but any other attempts at increasing or decreasing the # '/H's in the string failed to reveal a consistent behavior.

Reproduce code:
---------------
$sHayStack = "/data/virtual/abc.com/Home/test/absolute/Health";
$sNeedle = "/data/virtual/abc.com/Home/test/absolute";
echo ltrim( $sHayStack, $sNeedle );


Expected result:
----------------
Health

Actual result:
--------------
h

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-28 13:47 UTC] jani@php.net
Are you sure you're using the right function now?

string ltrim  ( string $str  [, string $charlist])

What you think is 'needle' is actually list of characters to remove.
It's not str_replace()..
 [2007-12-01 16:53 UTC] lowell at ietech dot com
Actually, I was looking for a more efficient way to remove the 'leading' string in lieu of ...
'strpos($haystack,$needle)==0?substr($haystack,strlen($needle)):$haystack;'

ltrim works great except for this anomaly.

I'm quite open to suggestions.  I have since created a function to satisfy this, but thought it best to still bring it to your attention.

Thanks for your input.
 [2007-12-19 17:34 UTC] felipe@php.net
.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 21:01:29 2024 UTC