Ok, after hours of bad research I ended up using a regular expression I found and parts of your example code:
$add_query = http_build_query($_GET);
$html_file = 'test.html';
$html = file_get_contents($html_file);
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $html, $regs, PREG_SET_ORDER)) {
foreach($regs as $reg) {
//href value
$link = $reg[2];
//If link contains a query
if (parse_url($link, PHP_URL_QUERY)) {
$mlink = $link.'&' . $add_query;
} else {
$mlink = $link.'?' . $add_query;
}
//Repalce in html
$html = str_replace($link, $mlink, $html);
}
}
echo $html;
Does the job, but your way is probably a lot better if I could get simpleXML to work.
Is there away or using preg_replace rather than str_replace? I had a go, but couldn't get it to work.