I\'m using DOM to parse string. I need function that strips span tags and its contents. For example, if I have:
This is some text that contains photo.
Try removing the spans directly from the DOM tree.
$dom = new DOMDocument(); $dom->loadHTML($string); $dom->preserveWhiteSpace = false; $elements = $dom->getElementsByTagName('span'); while($span = $elements->item(0)) { $span->parentNode->removeChild($span); } echo $dom->saveHTML();