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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
7 + 29 = ?
Subscribe to this entry?

 
 [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: Thu Apr 25 14:01:31 2024 UTC