Home > php教程 > php手册 > body text

php模板原理讲解

WBOY
Release: 2016-06-13 09:30:54
Original
1073 people have browsed it

复制代码 代码如下:


$data = array(
        'title'=>'ilsea',
        'list'=>array(
                'hello',
                'world'
            )
    );

include('show.php');

// show.php 模板文件


        echo $data['title'];
    echo '
';
    print_r($data['list']);
    ?>


定义一个函数用来包含模板,并传递数据

复制代码 代码如下:


// 定义一个函数用来包含模板,并传递数据,应该定义在公用函数库里的,这里我就直接写在这儿了
function template($template,$data)
{
    if(isset($data)){
        foreach($data as $key=>$val){
            $$key = $val;
        }
        unset($data);
    }
    include($template);
}

template('show.php',$data);


此例当然不是完整的写法,仅仅是一个小小的示例,模板赋值的原理就是这样的。
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!