You could do a simple string replace like:
str_replace('href="', 'href="http://www.example.com/', $string);
or with domdocument:
$page = '<html><head></head><body><a href="simple"></a><h1>Hi</h1><a href="simple2"></a></body></html>';
$doc = new DOMDocument();
$doc->loadHTML($page);
$as = $doc->getElementsByTagName('a');
foreach($as as $a){
$a->setAttribute('href', 'http://www.example.com/' . $a->getAttribute('href'));
}
print_r($doc->saveHTML());
output:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head></head><body><a href="http://www.example.com/simple"></a><h1>Hi</h1><a href="http://www.example.com/simple2"></a></body></html>
This doesn't take into account absolute paths, you'll need a regex approach for that..
If the quote types vary you also will need to use a regex for the str_replace
example. Can do something like('|")
for that then use $1
to match the quote type.