I have a long string that contains multiple HTML links that looks like this:
<a href="example.com">My Link></a>
or
<a href="http://example2.com">A different Link</a>
etc.
I need to rewrite these links in PHP so that they send the traffic thru my redirector, so I can tell users they are now leaving to an external domain, etc. My redirector is located at mydomain.com/leaving.php. What I want to do is rewrite these links to something like this:
<a href="http://www.mydomain.com/leaving.php/[URL ENCODED LINK FROM ABOVE]">My Link>
Since not all urls have http:// to begin with I think I need to first strip those from all href links.
How can I grep the correct HTML links (ignoring image src) and url_encode them, and place them back in the original string.
EDIT: Just to clearify, I am not looking for help with the redirection part, just how to replace several URLs within a large string when they sometimes have http