Re: tricky preg_replace and how to escape the \{occurencenumber}
| From: | lallous | Date: | Fri, 16 Aug 2002 14:12:39 +0000 |
| Subject: | Re: tricky preg_replace and how to escape the \{occurencenumber} | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-112955@lists.php.net to get a copy of this message | ||
James,
Actually the interpreter will evaluate the '\1'. '1' . '\2' into one
string
before passing it to preg_replace
So it will yield up as I originally wrote it, and it won't work.
Elias
"Jason Wong" <php-general@gremlins.com.hk> wrote in message
news:200208161942.01916.php-general@gremlins.com.hk...
> On Friday 16 August 2002 19:49, lallous wrote:
> > <?
> > $fn = 'test.gif';
> >
> > echo preg_replace('/(.+?)(\..+?)/', '\1a\2', $fn);
> >
> > ?>
> >
> > This script will output 'testa.gif'
> >
> > now how can i make it produce 'test1.gif' ?
> >
> > if i replace the: '\1a\2' with '\11\2' it will understand to replace
with
> > occurence number 11 !
> > How can i escape the 2nd '1' so it is considered as a string an not
another
> > number.
>
> Try:
>
> echo preg_replace('/(.+?)(\..+?)/', '\1'. '1' . '\2',
> $fn);
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
>
> /*
> IBM's original motto:
> Cogito ergo vendo; vendo ergo sum.
> */
>