Re: Replace in a string with regex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Jul 22, 2009 at 11:01 AM, Ashley
Sheridan<ash@xxxxxxxxxxxxxxxxxxxx> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux