Home > php教程 > PHP源码 > body text

简单快速的php模板引擎

PHP中文网
Release: 2016-05-26 08:18:38
Original
1236 people have browsed it

简单快速的php模板引擎

1.调用

<?php
require &#39;view.php&#39;;
 
$view=new view();
 
//第一种设置输出参数的方法
$view->setAttr("title", "Variable example");
//第二种设置输出参数的方法
$view->array = array(
            &#39;1&#39; => "First array item",
            &#39;2&#39; => "Second array item",
            &#39;n&#39; => "N-th array item",
);
$view->j = 5;
//输入页头、内容、页脚
$view->display("header.php")->display(&#39;index.php&#39;)->display(&#39;footer.php&#39;)->render();
Copy after login

2.theme/views/index.php

{comment}
这是注释
{/comment}
{if $array}
  {foreach $array as $key => $value}
    {$key} => {$value}<br />
  {/foreach}
{else}
  {/*}这也是注释{*/}
  <p>Array is empty!</p>
{/if}
 
{$i = 1}
{while $i < $j}
  当前 no. {$i}<br />
  {$i++}
{/while}
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template