skip to Main Content

Using DomDocument to Replace an <a> tag with Text – PHP

I'm looking to replace <a> tag in string with some text. My code is as follows $string = 'This link <a href="somedomain.com">Some Domain</a> needs to be removed'; $domdocument = new DOMDocument(); $domdocument->loadHTML($string, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); $link = $domdocument->getElementsByTagName('a')[0]; $replacement_link =…

VIEW QUESTION
Back To Top
Search