PHP regular expression to remove tags in HTML document

html-parsing, php, preg-replace, regex

Solution

Avoid regular expressions whenever you can, especially when processing xml. In this case you can use `strip_tags()` or simplexml, depending on your string.

Problem

Say I have the following text ``` ..(content)............. <A HREF="http://foo.com/content" >blah blah blah </A> ...(continue content)... ``` I want to delete the link and I want to delete the tag (while keeping the text in between). How do I do this with a regular expression (since the URLs will all be different) Much thanks

Original source

Related problems