News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

regex, embedded tags.

Started by Tyris, November 12, 2003, 02:44:52 AM

Previous topic - Next topic

Tyris

well... school and exams are over for ever...
time to PARTY!!
and by party I mean code...

so here's my current dillema I'm working on till SMF is released:
I basically want to be able to imbed tags...
the tag would basically be an <if blah>blahblah</if> where "blah" is a membergroup or groups, and "blahblah" is what is shown if the user is that membergroup.

Basically my problem is I need it to parse from the inside first... ie not select like so:
<if blah>
  <if blah>
    {$stuff}
  </if>
  {$otherstuff}
</if>
I was thinking of making the first <if blah> greedy... so it chooses the first one... then the </if> not greedy so it chooses the first one (obviously the <if and </if> 's are removed after they're parsed so if I can choose the middle ones first it'll work).

Just wondering if I'm on the right track... and if there's a faster/better or proper method I should be using to do this...

Thanx in Advance :)

*edit* also note: I'm a complete (well no longer complete) n00b at regex so go easy ;D

*edit 2*

ok... I managed to chuck together this:
$oldcontent = '';
while($oldcontent != $content)
{
$oldcontent = $content;
$content = preg_replace("~(.*)<if (.*?)>(.*?)</if>~is", "\\1--open--\\2--\\3--close--", $content);
}

the part that replaces atm is just there so I can read the source output... it was a test basically to see if it works... and it does... when I use it properly it'll use a function instead..
now my question is... is there a way to make it faster!?!? ;D

Advertisement: