php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53363 substr_count cannot find a \n when in a string with \r\n
Submitted: 2010-11-20 11:03 UTC Modified: 2010-11-20 13:47 UTC
From: apanatshka dot thedragoncouncil at gmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.3.1RC1 OS: Windows XP SP 3
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: apanatshka dot thedragoncouncil at gmail dot com
New email:
PHP Version: OS:

 

 [2010-11-20 11:03 UTC] apanatshka dot thedragoncouncil at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.substr-count#Description
---
substr_count cannot find a newline when in a string with a carriage 
return and newline right after eachother

Test script:
---------------
<?php
echo substr_count("\n", "\n");
echo substr_count("\n", "\r\n");
echo substr_count('
', "\r\n");
//I've changed the following simple string in my script so it only holds a newline character
echo substr_count('
', "\n");
//I've changed the following simple string in my script so it only holds a newline character
echo substr_count("\n", '
');
echo substr_count("\n", '
');
echo substr_count('
', '
');
?>

Expected result:
----------------
1111111

Actual result:
--------------
1011101

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-20 12:10 UTC] felipe@php.net
-Package: Reflection related +Package: Strings related
 [2010-11-20 12:16 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2010-11-20 12:16 UTC] felipe@php.net
Makes no sense substr_count("\n", "\r\n") returns 1. There is no "\r\n" in "\n".
 [2010-11-20 13:47 UTC] apanatshka dot thedragoncouncil at gmail dot com
my bad, it's haystack first, then needle... I thought it was the other way around
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 03:01:27 2024 UTC