php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #61926 strpos that finds multiple positions
Submitted: 2012-05-03 17:23 UTC Modified: 2018-08-14 15:37 UTC
Votes:2
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: abdallah at gmx dot com Assigned:
Status: Suspended Package: *General Issues
PHP Version: 5.4.1 OS: any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: abdallah at gmx dot com
New email:
PHP Version: OS:

 

 [2012-05-03 17:23 UTC] abdallah at gmx dot com
Description:
------------
I think we need a better strpos that can find multiple positions (an array) quickly.
to avoid the use of functions like :

$str = "&foobar&foobaz";
$toFind = "foo";
$start = 0;
while( ($pos = strpos(($str),$toFind,$start) !== false)) {
        echo 'Found '.$toFind.' at position '.$pos."\n";
        $start = $pos+1; // start searching from next position.
}

//Output:
   // Found foo at position 1
   // Found foo at position 8


Expected result:
----------------
an array of all positions

Actual result:
--------------
a simple position

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-14 15:37 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2018-08-14 15:37 UTC] cmb@php.net
I doubt that adding yet another string function for a somewhat
rarely needed functionality, which can easily be implemented in
userland, is reasonable.

So this would need discussion on the internals@ mailing list, and
likely an RFC.  Feel free to start the RFC process[1]. For the
time being, I'm suspending this ticket.

[1] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 11:01:30 2024 UTC