How can I use regex to retrieve all html tag names within an html snippet? I’m using PHP to do this if it matters. For example:
<div id="someid">
<img src="someurl" />
<br />
<p>some content</p>
</div>
should return: div, img, br, p.
Regexes might not always work. If you’re 100% sure that it’s well formed XHTML, regexes could be a way to do it though. If not, use some sort of PHP library to do it. In C#, there is something called the HTML Agility Pack, http://htmlagilitypack.codeplex.com, e.g. see How do I parse HTML using regular expressions in C#?. Maybe there is an equivalent tool in PHP.