ID: 49208 Updated by: j...@php.net Reported By: emil at nachev dot eu -Status: Open +Status: Bogus Bug Type: Strings related Operating System: Debian GNU/Linux PHP Version: 5.2.10 New Comment:
Can't reproduce either. Check your data. Previous Comments: ------------------------------------------------------------------------ [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