I wonder if there is any way to remove a specific tags from a php string?
I have knowledge of several features that make it, for example strip_tags, but what I really want is to remove tags containing the class attribute or any, I give an example below:
$string = '<p>Test paragraph.<p class="inner">Here is some inner text</p></p>';
How I can remove only the tag containing the class attribute ‘inner’?
If anyone can tell me a way to do this, I’d be grateful.
There’s no function to do that, and to avoid using a horrible regular expression the best way would be to load it into a
DOMDocumentclass and iterate over the tags in the string. You can then selectively remove tags depending on the class attribute and then write it back out to a string.See http://php.net/manual/en/class.domdocument.php for the documentation.