I am trying to remove specific links based on their ID tag, but leave the contents of the link. For example, I want to turn
Some text goes <a href="http://www.domain.tdl/" id="remove">here</a>
to
Some text goes here
I tried using below.
$dom = new DOMDocument; $dom->loadHtml(mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8")); $xp = new DOMXPath($dom); foreach($xp->query('//a[contains(@id="remove")]') as $oldNode) { $revised = strip_tags($oldNode); } $revised = mb_substr($dom->saveXML($xp->query('//body')->item(0)), 6, -7, "UTF-8"); echo $revised;
crudely taken from here , but it just discards the same contents of $html .
Any idea on how I will achieve this?
Jack
source share