|
Posted by Alan Little on 05/19/06 13:18
Carved in mystic runes upon the very living rock, the last words of Baron
Samedi of comp.lang.php make plain:
> I want to extend the PHP based blog system which I use.
>
> We have static templates for the various blog pages and I would like to
> introduce some logic to them.
>
> That is, I want to have some sort of structure, like
>
> [[if <condition>]]
> [[else]]
> [[endif]]
>
> or [[for 0, 3]] // do 4 time
> [[endfor]]
>
> but I am bogged down at the very first hurdle, which is just evaluating
> something like '2 == 2.".
>
> The text from the templates will be seen as a string, of course, but
> when I try to evaluate it as a bool,
> echo 'Evaluated condition: "' . (bool) $text . '"<br>';
>
> it always evaluates to true, even if my condition is '2 == 3'.
Strings and non-zero numbers evaluate to TRUE. You might consider the
eval() function.
eval('$condition = ($text)? true : false;');
if ($condtion) {
}
The usual caveats about not trusting visitor input apply.
I have a template processor I've been developing, that might work for
you. It's kind of a work-in-progress, but I've used it in production
environments. Email me if you'd like a copy.
--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Navigation:
[Reply to this message]
|