/ Published in: PHP

Match nested html elements using regular expressions.
Replace the first part of the magic "[a-z]+" to search for a specific tag, e.g. "div".
Loop the magic on matched parts to create a recursive match.
Replace the first part of the magic "[a-z]+" to search for a specific tag, e.g. "div".
Loop the magic on matched parts to create a recursive match.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// dummy html $html = '<div id="a1"><div id="a1-1"></div><div id="a1-2"></div></div><div id="a2"></div>'; // the magic // print result
Comments
