#37913 [Bgs->Opn]: preg_match_all typo

From: Date: Mon, 26 Jun 2006 09:30:28 +0000
Subject: #37913 [Bgs->Opn]: preg_match_all typo
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969373402@lists.php.net to get a copy of this message
ID: 37913 User updated by: tom at foreignproperty dot com Reported By: tom at foreignproperty dot com -Status: Bogus +Status: Open Bug Type: Documentation problem PHP Version: Irrelevant New Comment: 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]? Previous Comments: ------------------------------------------------------------------------ [2006-06-26 08:40:08] 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 08:16:06] 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"; << ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=37913&edit=1

« previous php.doc (#969373402) next »