Jump to content

Brentley_11

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Posts posted by Brentley_11

  1. I am writing a template parsing engine and I came across the need to parse some very complicated tags.  Here is an example:

     

    Input:

    Before{{{test}}}After
    {{{array[1]}}}
    {{{object->bandana('banana')}}}

     

    Output (If it worked):

    Before<?php echo TemplateVars::getVar("test"); ?>After
    <?php echo TemplateVars::getVar("array")[1]; ?>
    <?php echo TemplateVars::getVar("object")->bandana('banana'); ?>

     

    The php code I am using to parse this is:

    $regex = '/[{]{3}([\w]+)([\-\[=>\W]*)([\w\(\'"]*)([\]\)]*)[}]{3}/U';
    preg_replace($regex,'<?php echo TemplateVars::getVar("$1")$2$3$4; ?>',$data);

     

    Unfortunately that outputs the following:

    Before<?php echo TemplateVars::getVar("t")est; ?>After
    <?php echo TemplateVars::getVar("array")[1]; ?>
    <?php echo TemplateVars::getVar("object")->bandana('banana'); ?>

     

     

    I have also tried stuff like:

    $regex = '/[{]{3}([\w]+)([^}.]*)[}]{3}/U';

     

    But that gives every tag the same results as {{{test}}}.

     

    Any help is appreciated. Also if I need to elaborate more just ask.

  2. Everything still validates.  ???

    Code:
    [code]$test = array("Test","Test_11","Test.11","TEST","test","()Test");
    echo "Test2 <br>";
    foreach ($test  as $var){
    echo $var." - ";
    if(!ereg("[A-Za-z0-9_-]+",$var)) echo "Doesn't validate";
    else  echo "Does validate";
    echo "<br>";
    }[/code]

    Output:
    [code]Test2
    Test - Does validate
    Test_11 - Does validate
    Test.11 - Does validate
    TEST - Does validate
    test - Does validate
    ()Test - Does validate[/code]
  3. Is there a chance that I have php configured wrong? I just tested what you said and it didn't work.

    [code]$test = array("Test","Test_11","Test.11","TEST","test","()Test");

    foreach ($test  as $var){
    echo $var." - ";
    if(!ereg("[A-Za-z0-9_-]*",$var)) echo "Doesn't validate";
    else  echo "Does validate";
    echo "<br>";
    }[/code]

    This was the output:
    [code]Test - Does validate
    Test_11 - Does validate
    Test.11 - Does validate
    TEST - Does validate
    test - Does validate
    ()Test - Does validate[/code]

    The third and last one shouldn't validate.
×
×
  • 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.