Fixed up a bit of grammar and added a note about backrefs and backslashes.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@42344 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Torben Wilson 2001-03-01 00:19:18 +00:00
parent 1a28d541fd
commit 0f82660477

View file

@ -259,9 +259,10 @@ preg_match_all ("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",
<example>
<title>Find matching HTML tags (greedy)</title>
<programlisting role="php">
// the \\2 is an example of backreferencing. This tells pcre that
// it must match the 2nd set of parenthesis in the regular expression
// itself, which would be the ([\w]+) in this case.
// The \\2 is an example of backreferencing. This tells pcre that
// it must match the second set of parentheses in the regular expression
// itself, which would be the ([\w]+) in this case. The extra backslash is
// required because the string is in double quotes.
$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;]*&gt;)(.*)(&lt;\/\\2&gt;)/", $html, $matches);