#49208 [Bgs]: strpos() does not match newlines at the end of $needle
ID: 49208
User updated by: emil at nachev dot eu
Reported By: emil at nachev dot eu
Status: Bogus
Bug Type: Strings related
Operating System: Debian GNU/Linux
PHP Version: 5.2.10
New Comment:
My bad, it was a browser issue. Firefox submits form data with \r\n for
some reason. I didn't think to look for \r\n, because all testing and
development is done on Debian.
Sorry to bother, and thanks for looking.
Previous Comments:
------------------------------------------------------------------------
[2009-08-10 18:57:14] jani@php.net
Can't reproduce either. Check your data.
------------------------------------------------------------------------
[2009-08-10 11:25:01] sjoerd-php at linuxonly dot nl
Thank you for your report.
I could not reproduce it. I get this instead:
This works: int(30)
This does not: int(31)
Note that you say you get int(33), where I get int(30). Both this and
your example not working can be explained if you have Windows-style line
endings in your file instead of Unix-style line endings. In other words,
you have \r\n at the end of the line instead of \n. If this is the case,
it is not a bug in PHP because middle\n does indeed not occur in the
text.
------------------------------------------------------------------------
[2009-08-10 10:31:56] emil at nachev dot eu
Description:
------------
If $needle is a string that ends with a newline, strpos() does not find
the string in the $haystack, although it is there.
Reproduce code:
---------------
$text = <<<TEXT
This is just some text, with
something in the middle
that has newlines around it.
TEXT;
// The text contains both needles below:
$result = strpos($text, "\nsomething in the middle");
echo 'This works: '; var_dump($result);
echo "\n<br>\n";
$buggy_result = strpos($text, "something in the middle\n");
echo 'This does not: '; var_dump($buggy_result);
Expected result:
----------------
I expect matching for both "\nsomething in the middle" and "something
in the middle\n" to return an integer. Matching for "something in the
middle", without the newline, returns int(33) (as expected).
Actual result:
--------------
I get boolean false when matching for a string with "\n" at the end of
$needle:
This works: int(32)
This does not: bool(false)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49208&edit=1
Thread (4 messages)