From 74466adb744db043d7c216c066431fa65c858397 Mon Sep 17 00:00:00 2001 From: Monte Ohrt Date: Thu, 20 Jul 2000 19:09:09 +0000 Subject: [PATCH] added example to preg_match_all() git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@28669 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/pcre.xml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/functions/pcre.xml b/functions/pcre.xml index 7805cc1477..3be3bc7293 100644 --- a/functions/pcre.xml +++ b/functions/pcre.xml @@ -225,6 +225,35 @@ preg_match_all ("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x", + + + Find matching HTML tags (greedy) + +$html = "<b>bold text<b>lt;a href=howdy.html>click me<a> + +preg_match_all("/(<w]+)[^>lt;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"; +} + + + This example will produce: + +matched: <b>bold text<b> +part 1: <b> +part 2: bold text +part 3: <b> + +matched: <a href=howdy.html>click me<a> +part 1: <a href=howdy.html> +part 2: click me +part 3: <a> + + See also preg_match, preg_replace,