I’d like to get to all the a href links within the html string and convert all of the links as follows:
<a href='www.google.com'>Google</a>
Would change to look like this…
<a href='www.mysite.com/link.php?URL=www.google.com'>Google</a>
Can anyone suggest how I do this?
<?php
require_once(‘simple_html_dom.php’);
// load the class
$html = new simple_html_dom();
// load the entire string containing everything user entered here
$string = "<html><body><base href='http://www.site.biz/clients/g/'><a href='www.google.co.uk'>Google</a><a href='http://www.yahoo.co.uk'>Yahoo</a></body></html>";
$return = $html->load($string);
$links = $html->find('a');
foreach ($links as $link)
{
var_dump($link);
}
?>
Have you tried something like