I'm looking for a way to transform this:
...<a href="showinfo:3875//[integer]">[inner content]</a>...
Into this:
...<a href="http://somelink.com/[inner content]">[inner content]</a>...
The context has multiple links a with other showinfo:[integer] values. (I can process those ones)
Thanks for any help, Bálint
Edit: Thanks to Kaiser's answer, here is the working snippet:
$html = $a;
$dom = new \DOMDocument;
@$dom->loadHTML( $html ); //Cannot guarantee all-valid input
foreach ($dom->getElementsByTagName('a') as $tag) {
// Fixed strstr order and added a != false check - the, because the string started with the substring
if ($tag->hasAttribute('href') && strstr($tag->getAttribute('href'), 'showinfo:3875') != false) {
$tag->setAttribute( 'href', "http://somelink.com/{$tag->textContent}");
// Assign the Converted HTML, prevents failing when saving
$html = $tag;
}
}
return $dom->saveHTML( $dom);
}