if语句在php模板中使用tpl [英] if statements in php templates using tpl

查看:483
本文介绍了if语句在php模板中使用tpl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何解析 {if game> 4} {somecontent} {/ if} 使用PHP的模板。

How can i parse {if game > 4}{somecontent}{/if} from a template using PHP.

使用普通的旧PHP? ($ game> 4):?>更快更简单。

What's wrong with using plain old PHP? It's much faster and a whole lot simpler.

<?php if ( $game > 4 ): ?>
some content
<?php endif ?>

如果你真的坚持,这是一个开始(未经测试):

If you really insist, here's a start (untested):

<?php
preg_match_all('/\{if ([^}]+)\}.+?\{\/if\}/s', $content, $matches)

foreach ( $matches as $match )
{
    $expression = $match[1];

    // Evaluate expression

    $content = preg_replace($match[0], $true ? $match[1] : '', $content);
}
?>

这非常简单,当您想要使用嵌套语句时,它会变得非常多毛。

This is pretty simple, it get's really hairy when you want to work with nested statements.

这篇关于if语句在php模板中使用tpl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆