How can i strip <h1>including this content</h1>
<h1>including this content</h1>
I know you can use strip tags to remove the tags, but i want everything in between gone as well.
Any help would be appreciated.
As you’re dealing with HTML, you should use an HTML parser to process it correctly. You can use PHP’s DOMDocument and query the elements with DOMXPath, e.g.:
$doc = new DOMDocument(); $doc->loadHTML($html); $xpath = new DOMXPath($doc); foreach ($xpath->query('//h1') as $node) { $node->parentNode->removeChild($node); } $html = $doc->saveHTML();
1.4m articles
1.4m replys
5 comments
57.0k users