FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


A very small PHP contest





Mgccl
Reward: yes, I put this before telling you guys what is the contest about.
*A link to your site on http://www.webdevlogs.com
*A review of your site on http://www.webdevlogs.com

Note: The reward does not apply to sites with content higher than R(ex. NC-17)).

The challenge:
Suppose you want to make a template system that complies the template syntax into PHP script(like smarty), and you want to implement a while loop system.
All you want to do is change this syntax
Code:
{while $expression}output stuff{/while}

into

Code:
<?php while($expression){ ?>
output stuff
<?php } ?>

This is easy, but what if you suddenly want to let user to know the iteration of the loop? Now, the template will be like this
Code:
{while $expression}output stuff, and here out put the iteration:{$iteration}{/while}


you can compile it into this

Code:
<?php
$iteration = 1;
while($expression){ ?>
output stuff, and here out put the iteration:

<?php ++$iteration;} ?>



Ok, everything is fine, and here you will meet the CHALLENGE.
If the loop are nested, like:
Code:
{while $expression}{while $expression2}output stuff{$iteration}{/while}{$iteration}{/while}

How could you create a system that will know the right iteration for each one of the while loop so when {$iteration} is used, it is showing the iteration for the while loop it is in right now.

How the winner is decided:
The winner is the person writes a template parser that makes this template get complied and show the right result with the lowest time usage.

Code:
<?php
$timeparts = explode(' ',microtime());
$starttime = $timeparts[1].substr($timeparts[0],1);
$i = 0;?>
{while $i<30}
<?php $n = 0;?>
{while $n < 20}
$n+1:{$iteration}<br />
{/while}
$i+1:{$iteration}<br />
{/while}
<?php
$timeparts = explode(' ',microtime());
$endtime = $timeparts[1].substr($timeparts[0],1);
echo 'Time used:',bcsub($endtime,$starttime,6);
?>
Related topics
Hello from Boston
Looking for easy FormMail Script
A small PHP script request(like SO small), High pay
php/HTML pages question
What is the best free blogging site/software, and why?
$_COOKIE and $_SESSION help needed!
small php+mysql script, big reward
Harry Potter and the Deathly Hallows
PHP and cookies. Simple problem.
Why not to make easier
Embed PHP+HTML
Session directory permissions issue
PHP Fatal Error (Issue Resolved)
Fetch Alexa Rank of website using PHP function easily
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.