Jump to content

More REGEX problems


Synook

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

Oh - I see... but what about for the replacement argument? I don't see how I could use that.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...