php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55180 substr return is fail
Submitted: 2011-07-11 07:52 UTC Modified: 2011-07-11 12:09 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jonasvdegn at hotmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.3.6 OS: Windows 7
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jonasvdegn at hotmail dot com
New email:
PHP Version: OS:

 

 [2011-07-11 07:52 UTC] jonasvdegn at hotmail dot com
Description:
------------
the substr(string,from,to) failed and return something i find strange, and never seen it before..

my version is also 5.3.5 but i chose 5.3.6 because the 5.3.5 is not there.

Test script:
---------------
$x=1;
while ($x<=strlen("hello"))
{
$xx=$x-1;
echo substr("hello",$xx,$x);
$x++;
}
echo "<br/>";

$x=1;
while ($x<=strlen("hello"))
{
$xx=$x-1;
echo $xx." ";
echo $x." ";
echo substr("hello",$xx,$x);
echo "<br/>";
$x++;
}

Expected result:
----------------
i expect a result saying:

hello
0 1 h
1 2 e
2 3 l
3 4 l
4 5 o

like in substr("hello",0,1) substr("hello",1,2) and continue like that.

Actual result:
--------------
the actual result is:

hellloloo
0 1 h
1 2 el
2 3 llo
3 4 lo
4 5 o

like substr("hello",1,2) is "el" how can that be?
and  substr("hello",2,3) is "llo" and how can that be too?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-11 12:09 UTC] aharvey@php.net
-Status: Open +Status: Bogus -Package: Output Control +Package: Strings related
 [2011-07-11 12:09 UTC] aharvey@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.

The third parameter for substr() is the number of characters to return, not the 
end position.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC