Page 1 of 1

preg_replace

Posted: Tue Jan 31, 2006 10:01 am
by abalfazl
Hello firends

http://www.php.net/manual/en/function.preg-replace.php

May someone give me example about this:

"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, would 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. "



GOOD LUCK!

Posted: Tue Jan 31, 2006 10:16 am
by feyd
what, in particular, are you trying to understand or are confused about?

Posted: Tue Jan 31, 2006 11:14 am
by Chris Corbyn

Code: Select all

<?php

$string = "I want to make this ten (10) into one hundred and one";

echo preg_replace('/(\d+)/', "\\11", $string);
echo preg_replace('/(\d+)/', "\${1}1", $string);

?>