Simplest way to convert all html links in a string using PHP

Posted by Gaz on Stack Overflow See other posts from Stack Overflow or by Gaz
Published on 2012-04-02T10:50:00Z Indexed on 2012/04/02 11:30 UTC
Read the original article Hit count: 275

Filed under:
|
|
|
|

I am trying to convert a block of text that contains html text - i'd like to find all http links and convert them for link tracking purposes.

So eg anything like this in a string would be converted to the latter

<a href="http://www.google.com">Some Link</a>

<a href="http://www.mysite.com/tracking.php?url=www.google.com">Some Link</a>

Can anyone how to do this taking into account the original string will consists of all sorts of html, images etc..

© Stack Overflow or respective owner

Related posts about php

Related posts about regex