added example to preg_match_all()

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@28669 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Monte Ohrt 2000-07-20 19:09:09 +00:00
parent 1c6012e384
commit 74466adb74

View file

@ -225,6 +225,35 @@ preg_match_all ("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",
</programlisting>
</example>
</para>
<para>
<example>
<title>Find matching HTML tags (greedy)</title>
<programlisting role="php">
$html = "&lt;b&gt;bold text&lt;b&gt;lt;a href=howdy.html&gt;click me&lt;a&gt;
preg_match_all("/(&lt;w]+)[^&gt;lt;2&gt; $html, $matches);
for($i=0; $i&lt; 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";
}
</programlisting>
</example>
This example will produce:
<programlisting>
matched: &lt;b&gt;bold text&lt;b&gt;
part 1: &lt;b&gt;
part 2: bold text
part 3: &lt;b&gt;
matched: &lt;a href=howdy.html&gt;click me&lt;a&gt;
part 1: &lt;a href=howdy.html&gt;
part 2: click me
part 3: &lt;a&gt;
</programlisting>
</para>
<simpara>
See also <function>preg_match</function>,
<function>preg_replace</function>,