Hello,
I need to properly match a <ul></ul> block in list menu. If I try to determine the end of the block by the first closing </ul> I come to I'll get a false positive if it hits the closing </ul> of an inner nested <ul> block.
Somehow, the comparison needs to keep count of how deep it is inside the nesting, and make sure the number of closing </ul>s equals the number of opening <ul>s before it considers the pattern matched.
Thanks in advance for your help!
Rocco
matching nested <ul> lists
Moderator: General Moderators
-
dancing dragon
- Forum Newbie
- Posts: 8
- Joined: Sun Aug 17, 2008 4:57 am
- Location: bed
Re: matching nested <ul> lists
I think your answer is in your question. Have a variable keep count of how deep the parsing is inside the nesting. When you hit an opening <ul>, depth++. When you hit a closing </ul>, depth--, relative from your starting point of depth = 0.rocco2004 wrote: Somehow, the comparison needs to keep count of how deep it is inside the nesting, and make sure the number of closing </ul>s equals the number of opening <ul>s before it considers the pattern matched.
Is that what you're looking for?
Last edited by dancing dragon on Mon Aug 18, 2008 9:09 am, edited 1 time in total.
Re: matching nested <ul> lists
Hello again,
Yes, counting nested ul may be an option but I'm not sure what function to use. I need to somehow loop through ul elements within the string and count their deepens. How should I do that?
Thanks
Rocco
Yes, counting nested ul may be an option but I'm not sure what function to use. I need to somehow loop through ul elements within the string and count their deepens. How should I do that?
Thanks
Rocco
-
dancing dragon
- Forum Newbie
- Posts: 8
- Joined: Sun Aug 17, 2008 4:57 am
- Location: bed
Re: matching nested <ul> lists
How about something like function preg_split where you split on the regular expression of <ul> OR </ul>? That would be something like "/(<ul>)|(<\/ul>)/" . (I haven't tested that. There could be bugs in there.)
And you would probably need to use the flag PREG_SPLIT_DELIM_CAPTURE to know which delimiter each split was made on.
That's one idea. I don't know if there are better options.
And you would probably need to use the flag PREG_SPLIT_DELIM_CAPTURE to know which delimiter each split was made on.
That's one idea. I don't know if there are better options.