Okay, so I've been working on a PHP/SQL blogware for some little while now and I've been getting into working on the template parser and I need a little bit of help with switches and loops.

For the record, I mean like what phpBB uses

Code:
      <!-- BEGIN switch_user_logged_out -->
      <!-- END switch_user_logged_out -->
and
Code:
       <!-- BEGIN catrow -->
         <!-- BEGIN forumrow -->
         <!-- END forumrow -->
       <!-- END catrow -->

How would I go about coding something like this? Searching through phpBB's files is a fruitless endeavor a majority of the time and I don't know what keywords to google. Neutral
Try taking a look at the pear package HTML_TEMPLATE_IT it should accomplish that.
Well, if you still want to write something from scratch, you can use the regex routines to at least find the line and sections to match using:


Code:
// assumes lines of template are all in $lines
// uses $switches as an inverted LIFO queue of section names

$switches = array();
foreach($lines as $thisline) {
    if (preg_match('/<!-- BEGIN ([^\s]+) -->/',$thisline,&$matches)) {
        $inswitchdepth++;
        array_unshift($switches,$match[1]);
    }
    if (preg_match('/<!-- END ([^\s]+) -->/',$thisline,&$matches)) {
        if (array_shift($switches) == $matches[1]) {
            $inswitchdepth--;
        } else {
            die('FATAL: tag mismatch');
        }
    }
}
      <!-- END switch_user_logged_out -->
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement