Page 1 of 1

function within regular expression

Posted: Mon Jul 31, 2006 7:27 am
by bvdv
Hello ik have a regular expression to replace all urls
this is

Code: Select all

$elm1= preg_replace('/<a href="(.*?)">(.*?)<\\/a>/i', '<a href="linkto.php?param3=$1[urlklik]">$2</a><br>', $elm1);
but i want to do an encoding somthing like this

Code: Select all

$elm1= preg_replace('/<a href="(.*?)">(.*?)<\\/a>/i', '<a href="linkto.php?param3='.(base64_encode(serialize($1))).'[urlklik]">$2</a><br>', $elm1);
but the problem is that if the $1 is outside the quote's the parser tels me that $1 does not exist can someone point me in the right direction


greetings Bert

Posted: Mon Jul 31, 2006 7:35 am
by ambivalent

Posted: Mon Jul 31, 2006 7:41 am
by Oren
He is not using variables, the $1 and the $2 are backreferences.

Posted: Mon Jul 31, 2006 7:44 am
by ambivalent
Oren wrote: He is not using variables, the $1 and the $2 are backreferences.
Oops....never mind then. 8O

Posted: Mon Jul 31, 2006 7:53 am
by Oren
Check out this: preg_replace_callback