|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22366 PREG_OFFSET_CAPTURE produces error with preg_match_all
Submitted: 2003-02-21 17:01 UTC Modified: 2003-02-23 02:52 UTC
From: csaba at alum dot mit dot edu Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.3.0 OS: Win 2K
Private report: No CVE-ID: None
 [2003-02-21 17:01 UTC] csaba at alum dot mit dot edu
The following code gives me an error message of:
Wrong value for parameter 4 in call to preg_match_all() ...

if I replace the PREG_OFFSET_CAPTURE with either
then it works as advertised.
This contradicts the documentation statement:
If no order flag is given, PREG_PATTERN_ORDER is assumed

$page = "<html><head></head><body><form>" .
        "<input onClick='alert(\"Hi Mom\")' " .
        "value='Click me'>" .
        "<input onClick='alert(\"Hi Dad\")' " .
        "value=\"Dad's button\">" .

$regexp = "/<input[^>]*(value=[^>]*)>/";
if (!preg_match_all($regexp, $page, $mtch,
    print "<br>Could not match";
    else print "<br>Found matches";

This is on my PHP 4.3.0 / Apache 2.0.43 / Win 2K Pro system
Csaba Gabor from New York


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-23 02:52 UTC]
When you use preg_match_all() with only 3 paramaters,
then PREG_PATTERN_ORDER is assumed for order flag.

 [2004-01-02 01:27 UTC] eagleprof at yahoo dot com dot au
This is not a bogus bug. I can repeat it too. I have a Win2K/IIS 5.0 setup using PHP v4.3.2. 

As csaba says, the problem occurs when you have four parameters and attempt to pass the PREG_OFFSET_CAPTURE flag by itself as the fourth parameter. The workaround is to explicitly set the sort order with the PREG_OFFSET_CAPTURE flag.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Dec 01 04:01:29 2023 UTC