Recursive Regex Fun?
January 8, 2006 4:31 PM
Subscribe
Regexfilter: I'm using PHP and I want to match HTML span classes recursively/in a hierarchy. Help/pointers would be much appreciated.
Example string:
<span class="heading">This is</span><span class="bodytext">not a heading.</span>
I can match a string like this just fine using this regex:
<span class=\"(.*?)\">(.*?)</span> in preg_match_all. What I want to do is return a multi-dimensional array in case of nested spans, which currently confuse the hell out of my code (and me!). For example:
<span class="heading">This <span class="shiny"> is a</span> lovely heading</span>&span class="bodytext">bla bla.</span>
Thanks a million and one to all those that can help. :-)
posted by PuGZ to computers & internet (5 comments total)
posted by PuGZ at 4:32 PM on January 8, 2006