note 48069 deleted from function.preg-match-all by tularis

From: Date: Fri, 10 Dec 2004 13:21:19 +0000
Subject: note 48069 deleted from function.preg-match-all by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-81650@lists.php.net to get a copy of this message
Note Submitter: Find matching tags ---- $html = "<span>foo</span><span>bar</span>"; header('content-type: text/plain'); preg_match_all('/(<([\w]+)[^>]*>)(.*)(<\/\\2>)/', $html, $matches); for ($i=0; $i< count($matches[0]); $i++) { 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"; } Does anyone know how to match every single tag in the example above? I used the expression from the example, but it doesn't work for me, it works for <a>foo</a><b>bar</b> but not for multiple tags... <span>foo</span><span>bar</span> resulted in only one match... matched: <span>foo</span><span>bar</span> part 1: <span> part 2: foo</span><span>bar part 3: </span> I think the (.*) causes the problem because it matches every character which includes the 'foo</span><span>bar' piece of the string. ---- Reason: useless note

« previous php.notes (#81650) next »