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.