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?

Edited by The Little Guy
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.