pollita Mon Jan 20 14:52:12 2003 EDT
Modified files:
/phpdoc/en/reference/pcre/functions preg-replace.xml
Log:
Bug # 15166. Backreferences followed by numeric literals.
Index: phpdoc/en/reference/pcre/functions/preg-replace.xml
diff -u phpdoc/en/reference/pcre/functions/preg-replace.xml:1.3
phpdoc/en/reference/pcre/functions/preg-replace.xml:1.4
--- phpdoc/en/reference/pcre/functions/preg-replace.xml:1.3 Tue Jul 23 18:04:54
2002
+++ phpdoc/en/reference/pcre/functions/preg-replace.xml Mon Jan 20 14:52:12 2003
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.3 $ -->
+<!-- $Revision: 1.4 $ -->
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 -->
<refentry id="function.preg-replace">
<refnamediv>
@@ -34,6 +34,40 @@
<literal>\\0</literal> or <literal>$0</literal> refers to the text matched
by the whole pattern. Opening parentheses are counted from left to right
(starting from 1) to obtain the number of the capturing subpattern.
+ <note>
+ <para>
+ 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 <literal>\\1</literal>
+ notation for your backreference. <literal>\\11</literal>, for example,
+ would confuse <function>preg_replace</function> since it does not know whether
+ you want the <literal>\\1</literal> backreference followed by a literal
+<literal>1</literal>,
+ or the <literal>\\11</literal> backreference followed nothing. In this case
+ the solution is to use <literal>\${1}1</literal>. This creates an
+ isolated <literal>$1</literal> backreference, leaving the <literal>1</literal>
+ as a literal.
+ </para>
+ </note>
+ <example>
+ <title>Using backreferences followed by numeric literals.</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$str = "April 15, 2003";
+$pattern = "/(\w+) (\d+), (\d+)/i";
+$replacement = "\${1}1,\$3","April 15, 2003";
+print preg_replace($pattern, $replacement, $string);
+
+/* Output
+ ======
+
+April1,2003
+
+ */
+?>
+]]>
+ </programlisting>
+ </example>
</para>
<para>
If matches are found, the new <parameter>subject</parameter> will
--
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php