|  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
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 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.
Block user comment
Status: Assign to:
Bug Type:
From: abdallah at gmx dot com
New email:
PHP Version: OS:


 [2012-05-03 17:23 UTC] abdallah at gmx dot com
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.

   // Found foo at position 1
   // Found foo at position 8

Expected result:
an array of all positions

Actual result:
a simple position


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-14 15:37 UTC]
-Status: Open +Status: Suspended
 [2018-08-14 15:37 UTC]
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] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Apr 20 09:01:24 2021 UTC