function within regular expression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bvdv
Forum Newbie
Posts: 1
Joined: Mon Jul 31, 2006 7:19 am

function within regular expression

Post 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
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post by ambivalent »

User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

He is not using variables, the $1 and the $2 are backreferences.
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post by ambivalent »

Oren wrote: He is not using variables, the $1 and the $2 are backreferences.
Oops....never mind then. 8O
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Check out this: preg_replace_callback
Post Reply