For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > September 2006 > Re: preg_replace where replacement is an array element to which backreference value i









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: preg_replace where replacement is an array element to which backreference value i
Dave

2006-09-14, 6:57 pm

"Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net> wrote in message
news:w6hOg.12036$xQ1.10614@newsread3.news.pas.earthlink.net...
> On 09/14/2006 10:03 AM, Dave wrote:
>
> Use the /e option to evaluate the replacement string as PHP code:
>
> $arr = Array(3=>"aaa",104=>"bbb",345=>"ccc",'n'=>"etc");
> $html='<html>....<a href="page.php?var=3">3</a><a
> href="page.php?var=345">345</a> ...<a
> href="page.php?var=n">n</a>...</html>';
>
> $html = preg_replace('/(page\.php\?var=)(\w+)/sie',
> '"\1".$arr["\2"]',$html);
>
> print $html;
>


Aaaah, the life is so much better now.
I did try playing with e flag but the script was blowing up and I thought I
was using it wrong.
Your suggestion worked perfectly, Thank you!


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com