A general capture group can use 1N as the table name. if it uses P & amp; lt; xxx & amp; gt;, what is the name of the capture result in The Replacement parameter? {Code ...} it seems that k & amp; lt; xxx & amp; gt; is used directly. Otherwise, the average capture group can use \ 0 \ 1 \ N as the table name. if P is used In this way, what is used to represent the capture result in The Replacement parameter?
"; $text.=""; $text.=" some
"; $out=preg_replace("/<(?P
span|p)[^>]+>(.+)<\/(\k
)>/","[\P= TAG]\\1[\/\k
]",$text); print_r( $out);
It seems that k is used directly. This is not the case.
Reply content:
For a general capture group, \ 0 \ 1 \ N can be used as the table name. In this way, what is used to represent the capture result in The Replacement parameter?
"; $text.=""; $text.=" some
"; $out=preg_replace("/<(?P
span|p)[^>]+>(.+)<\/(\k
)>/","[\P= TAG]\\1[\/\k
]",$text); print_r( $out);
It seems that k is used directly. This is not the case.
Http://php.net/manual/en/function.preg-replace.php
Replacement may contain references of the form \ n or (since PHP
4.0.4) $ n, with the latter form being the preferred one. Every such reference will be replaced by the text captured by the n 'th
Parenthesized pattern. n can be from 0 to 99, and \ 0 or $0 refers
The text matched by the whole pattern. Opening parentheses are counted
From left to right (starting from 1) to obtain the number of
Capturing subpattern. To use backslash in replacement, it must be
Doubled ("\" PHP string ).
When working with a replacement pattern where a backreference is
Immediately followed by another number (I. e.: placing a literal number
Immediately after a matched pattern), you cannot use the familiar \ 1
Notation for your backreference. \ 11, for example, wocould confuse
Preg_replace () since it does not know whether you want the \ 1
Backreference followed by a literal 1, or the \ 11 backreference
Followed by nothing. In this case the solution is to use $ {1} 1. This
Creates an isolated $1 backreference, leaving the 1 as a literal.
When using the deprecated e modifier, this function escapes some
Characters (namely ', ", and NULL) in the strings that replace
This is done to ensure that no syntax errors arise
Backreference usage with either single or double quotes (e.g.
'Strlen ('$ 1') + strlen ("$2")'). Make sure you are aware of PHP's
String syntax to know exactly how the interpreted string will look.