0

Given the following markup:

<tag>foo</tag><another /> <tag class="a">bar</tag> <tag-footer>foot</tag-footer><tag />

and passed 'tag' as the desired one to remove, I need to end up with:

foo <another />bar <tag-footer>foot</tag-footer>

If the tag to remove is self-closing it should handle that too.

I've come close using preg_replace in two passes (one for the opening tag and another for the closing) or one pass for a self-closing tag, but it removed both 'tag' and 'tag-footer'.

In another attempt, it removed both 'tag' and 'another', having decided that anything between the opening < and an eventual > was fair game.

This is NOT a duplicate of the question cited at all. I do not want the text between tags deleted, which is what that question wants...I want just the tags themselves deleted. And there is the issue of a tag name that is a substring of a different tag name being an issue in the regex.

JAyenGreen
  • 1,385
  • 2
  • 12
  • 23
  • It's a job for DOM tools not Regular Expressions. Besides why `` isn't in your desired output? – revo Jul 26 '17 at 07:03
  • Sorry. Edited the desired output. DOM would be fine if PHP had a innerHTML method. Leaving the content between tags would seem a kluge without it. – JAyenGreen Jul 26 '17 at 13:02

0 Answers0