内部带有<?PHP?>标签的PHP create_function

I´m building a MVC style parser, and I NEEDto be able to process my custom tags (used with the {} separator, like {echo $myVar}) together with standard PHP code <?php doSomething ?> in the same file...

So, after running my parser (that deals with the {} scope), I get the following result:

if (is_Array($data) && sizeof($data)) extract($data); 
$text = array();$text[] = "
<div class=\"row\">

            <strong>Name: </strong>";$text[] =  $name;$text[] = "<br /> 
            <strong>Description:</strong>";$text[] =  $description;$text[] = "
            <br /> 

            <strong>Status: </strong>
            <?php if ($status == false) : ?>
                <span class=\"label label-danger\">FAILURE</span>
            <?php else : ?>
                <span class=\"label label-success\">OK</span>
            <?php endif; ?> 
            <br />
    </div>
";return implode($text);

All fine. From that piece of code I create a function using:

function = create_function("\$data", $code); 

$code is the resultset from above. $data is an array containg variables and values like:

`$name` => jonas
`$description` => This is test.
`$status`=> false

Finally I run:

$ret = $function($data);
echo $ret;

At that point, I get a problem. All references to variables are removed, but the tags are not processed, resulting in a kind of wierd code like:

<div class="row">

            <strong>Name: </strong>jonas"<br /> 
            <strong>Description:</strong>This is test.<br /> 

            <strong>Status: </strong>
            <?php if ( == false) : ?>  <<<<<========== WRONG CODE
                <span class=\"label label-danger\">FAILURE</span>
            <?php else : ?>
                <span class=\"label label-success\">OK</span>
            <?php endif; ?> 
            <br />
    </div>

So, the variables are substituted, except for the code that is neither solved nor have the variables correctly replaced.

I wish I can get a solution for that problem... Thanks for helping.

You're probably going about this in an inefficient manner...but to purely fix the problem you are having with your current code, just take the conditionals out of the quotations.

if (is_Array($data) && sizeof($data)) extract($data); 
$text = array();$text[] = "
<div class=\"row\">

            <strong>Name: </strong>";$text[] =  $name;$text[] = "<br /> 
            <strong>Description:</strong>";$text[] =  $description;$text[] = "
            <br /> 

            <strong>Status: </strong>";
            if ($status == false) :
                $text[] = "<span class=\"label label-danger\">FAILURE</span>";
            else :
                $text[] = "<span class=\"label label-success\">OK</span>";
            endif;
            $text[] = "<br />
    </div>
";return implode($text);

You must ecape the variable declaration, as it will be parsed by php. Then process your php code stored in a string with eval().