TypechoJoeTheme

至尊技术网

统计
登录
用户名
密码
/
注册
用户名
邮箱

悠悠楠杉

网站页面

PHP Smarty 模板引擎

2021-01-06
/
0 评论
/
980 阅读
/
正在检测是否收录...
01/06

1.php

<?php
class Mini
{
    protected $data = array();
    //把外界变量放进data数组
    public function assign($k, $v)
    {
        $this->data[$k] = $v;
    }
    public function comp($temp)
    {
        $html = file_get_contents($temp);
        //注意 下行引用自身的data属性
        $html = str_replace('{$', "<?php echo \$this->data['", $html);
        $html = str_replace('}', "'];?>", $html);
        $compfile = $temp . '.php';
        file_put_contents($compfile, $html);
        return $compfile;
    }
    public function display($temp)
    {
        $compfile = $this->comp($temp);
        require $compfile;
    }
}
$sql = "select * from art";
$title = '今天不下雨,ε=(´ο`*)))';
$mini = new Mini();
$mini->assign('title', $title);
$mini->display('1.html');

1.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
</head>

<body>
    <p>{$title}</p>
</body>

</html>
经验PHP面向对象Smarty模板引擎
朗读
赞(0)
版权属于:

至尊技术网

本文链接:

https://www.zzwws.cn/archives/4999/(转载时请注明本文出处及文章链接)

评论 (0)