php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53951 Preg_match_all question/does not return ALL values
Submitted: 2011-02-07 19:38 UTC Modified: 2011-02-08 04:03 UTC
From: dtremblay dot fafard at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.5 OS: Linux
Private report: No CVE-ID: None
 [2011-02-07 19:38 UTC] dtremblay dot fafard at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.preg-match-all#Description
---

Preg_match_all does not get ALL results.

Test script:
---------------
preg_match_all("/abba/", "abbabba", $resultats);

foreach($resultats[0] as $resultat){
        echo $resultat;
}


Expected result:
----------------
I expect to get 2x abba found instead of 1.  I see 1x abba found.  It is specifically said that it will be 1 because it start the second search after the end of the last result found.  Why do it this way?  It is not that hard to start after the first character of the string found.  So  There must be some kind of performance reason, which I would like to understand.


This comes from the fact that I want to get ALL words in a sentence.  But all words are surrounded by white spaces.  So I have to put the white spaces in my regex. But because of that I HAVE to double the white spaces to get ALL words.  Which is something I would like to avoid for performance.

Please if you have time, send me an email to explain me why is it done that way.

Thank you in advance.

Actual result:
--------------
I see 1x abba found.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-08 04:03 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2011-02-08 04:03 UTC] aharvey@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 20:01:33 2025 UTC