Jump to content

More REGEX problems


Synook
 Share

Recommended Posts

Hello all,I have another problem with a REGEX. I want to replace all hyperlink markups in a string to add ?q= to the front of the href, using preg_replace, e.g. <a href="http://www.google.com"> to <a href="?q=http://www.google.com">. But I can't do it :)Any ideas?

Link to comment
Share on other sites

No what the... i've solved my problem again! Why does this always happen - 3 days frustration, I post, 10 minutes later - problem solved :)But - I still have another problem. I want to make it so that if the href=, say, "index.html" and I am at http://www.google.com, it will convert the href to http://www.google.com/index.html. But, if the original href is http://www.yahoo.com, then it will convert it to ?q=http://www.yahoo.com and not?q=http://www.google.comhttp://www.yahoo.comSo, any ideas on that one?

Link to comment
Share on other sites

$page = preg_replace("<a (.*?)href=\"(.*?)\"(.*?)>", "a $1" . "href=\"?address={$address}$2\"$3", $page);

(?q has been changed to ?address)The problem is, is there a way of doing conditional in REGEX?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...