php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #37913 preg_match_all typo
Submitted: 2006-06-26 08:16 UTC Modified: 2006-06-26 10:35 UTC
From: tom at foreignproperty dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tom at foreignproperty dot com
New email:
PHP Version: OS:

 

 [2006-06-26 08:16 UTC] tom at foreignproperty dot com
Description:
------------
In the description for preg_match_all, in the 2nd example, Find matching HTML tags (greedy), the part 2 and part 3 array values are wrong ($matches[3], $matches[4]).

  echo "matched: " . $matches[0][$i] . "\n";
  echo "part 1: " . $matches[1][$i] . "\n";
>>  echo "part 2: " . $matches[3][$i] . "\n";       <<
>>  echo "part 3: " . $matches[4][$i] . "\n\n";     <<





Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-26 08:40 UTC] takagi@php.net
No, that's perfectly correct.

The regx is "/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/".

So,
[1] correspond to (<([\w]+)[^>]*>),
[2] correspond to ([\w]+),
[3] correspond to (.*), and
[4] correspond to (<\/\\2>).

 [2006-06-26 09:30 UTC] tom at foreignproperty dot com
look at the array keys.
it goes $matches[0], $matches[1], then jumps to $matches[3] and $matches[4]

Shouldn't part 2 be matches[2], and part 3 be $matches[3]?
 [2006-06-26 10:35 UTC] nlopess@php.net
No. The example is correct. It shows how to use nested parenteses and backreferences.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Aug 02 03:00:02 2025 UTC