Jump to content

Execute if/else statements generated from a template


The Little Guy

Recommended Posts

I am making a template library I am extracting data from a template, like this one for example:

 

    <!DOCTYPE html>
    <html>
        <head>
            <title>If/Else</title>
        <body>
            $if($get.id == 0):
                <span style="color: green">GET is 0</span>
            $elseif($get.id == 1):
                <span style="color: yellow">GET is 1</span>
            $elseif($get.id == 2):
                <span style="color: yellow">GET is 2</span>
            $else:
                <span style="color: red">GET is not Set!</span>
            $endif;
        </body>
    </html>

 

What I have now, is I extract all the required data that I need between ( and ) for each if, elseif using some regexp. in my php have have the following after the data is extracted:

 

    <?php
    // Extrat the data and make these variables:
    $ifStmt = "$get.id == 0";
    $ifElseStmts = array(
        [0] => "$get.id == 1",
        [1] => "$get.id == 2"
    );

 

Now the question that I have is that need to evaluate each one until I find one that gives true as a result. I was thinking of doing eval, but that isn't really secure, so any suggestions on what I should do to evaluate the if statements?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.