manipulating preg_replace() variables
Posted: Mon Sep 10, 2007 12:38 pm
Let's say I want to change the href attribute to be an argument of another url for all my <a> elements. For example:
Change:
http://www.old.com
To:
http://www.new.com?url=[b]http//www.old.com[/b]
I need to urlencode the old url, but can't figure out how to do it. If I use:
preg_replace("\<a href='(.*)'(.*)\>", "<a href='http://www.new.com?url=".[b]urlencode("$1")[/b].".'$2>", $content);
Then, I get:
http://www.new.com?url=[b]%241[/b]
Meaning it's not recognizing the variable. Any ideas?
thanks in advance, Chuck
Change:
http://www.old.com
To:
http://www.new.com?url=[b]http//www.old.com[/b]
I need to urlencode the old url, but can't figure out how to do it. If I use:
preg_replace("\<a href='(.*)'(.*)\>", "<a href='http://www.new.com?url=".[b]urlencode("$1")[/b].".'$2>", $content);
Then, I get:
http://www.new.com?url=[b]%241[/b]
Meaning it's not recognizing the variable. Any ideas?
thanks in advance, Chuck