Re: Replace in a string with regex

From: Date: Wed, 22 Jul 2009 15:05:36 +0000
Subject: Re: Replace in a string with regex
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-295690@lists.php.net to get a copy of this message
On Wed, Jul 22, 2009 at 11:01 AM, Ashley Sheridan<ash@ashleysheridan.co.uk> wrote: > On Wed, 2009-07-22 at 07:54 -0700, Jim Lucas wrote: >> Sure that can be done.  But you will need to change the second argument >> to have double quotes so it will be parsed by PHP. >> >> Then I would surround YOUR variable with curly brackets to separate it >> from the rest. >> >> echo preg_replace('#(screens/)temp/.+?_1(_main\.jpg)#', >>                   "$1{$id}$3", >>                   $file); >> > I tested this, with the double quotes and the curly braces around the > middle argument (to avoid PHP getting confused) and it didn't recognise > the matches by the numbered $1, $3, etc. I know I'm not the op who asked > the original question, but it might help him/her? > > Thanks > Ash > www.ashleysheridan.co.uk Don't you also have to escape the $'s for the matches since it's in double quotes? "\$1{$id}\$3" Andrew

« previous php.general (#295690) next »