PHP模板引擎 phptpl

码农软件 · 软件分类 · 模板引擎 · 2019-08-23 12:58:25

软件介绍

phptpl是一个轻便的PHP模板引擎。不需要什么学习成本就能轻松掌握,简洁就是美。

一个简单的示例:

PHP模板文件 test_phptpl.html
<!-- template for testing phptpl -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>$TITLE$</title>
</head>
<body>
<center>$TABLE_HEADER$</center>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
    <!-- BEGIN $DETAIL$ SECTION -->
    <tr>
        <td>
            $USER_ID$
        </td>
        <td>
            $USER_NAME$
        </td>
    </tr>
    <!-- END $DETAIL$ SECTION -->
</table>
<!-- IF $LOGIN$ -->
<p>somebody login</p>
<!-- ELSE $LOGIN$ -->
<p>no user login</p>
<!-- ENDIF $LOGIN$ -->
</body>
</html>



测试phptpl文件 test_phptpl.php
<?php
/**
 * test phptpl
 */

require "phptpl.php" ;

// 字符串替换配置
$str_replace_array['$TITLE$'] = "test_phptpl" ;
$str_replace_array['$TABLE_HEADER$'] = "MY_TABLE_HEADER" ;
// 明细替换配置
function detail_function( $in_str = null , $print_flag = false )
{
    if( $in_str == null )
        return null;
    
    $out_str = "" ;
    for( $i = 1 ; $i <= 3 ; $i++ )
    {
        $str_replace_array = array() ;
        $str_replace_array['$USER_ID$'] = "MY_TITLE_" . (string)$i ;
        $str_replace_array['$USER_NAME$'] = "MY_USER_NAME_" . (string)$i ;
        
        $out_str .= phptpl_str( $in_str , $str_replace_array , null , null , null , false ) ;    
    }
    
    if( $print_flag == true )
        print $out_str ;
    
    return $out_str;
}
$section_replace_array['$DETAIL$'] = "detail_function" ;
// 区域存在配置
$if_exist_array['$LOGIN$'] = true ;
// 执行模板处理并立即输出
phptpl_file( "test_phptpl.html" , $str_replace_array , null , null , $if_exist_array , $section_replace_array , true );
?>



执行test_phptpl.php后输出
<!-- template for testing phptpl -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test_phptpl</title>
</head>
<body>
<center>MY_TABLE_HEADER</center>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
    <tr>
        <td>
            MY_TITLE_1
        </td>
        <td>
            MY_USER_NAME_1
        </td>
    </tr>
    <tr>
        <td>
            MY_TITLE_2
        </td>
        <td>
            MY_USER_NAME_2
        </td>
    </tr>
    <tr>
        <td>
            MY_TITLE_3
        </td>
        <td>
            MY_USER_NAME_3
        </td>
    </tr>
</table>
<!-- IF $LOGIN$ -->
<p>somebody login</p>
</body>
</html>




本文地址:https://www.codercto.com/soft/d/12992.html

ASP.NET 2.0入门经典

ASP.NET 2.0入门经典

哈特 / 清华大学出版社 / 2006-8 / 78.00元

该书是Wrox红皮书中的畅销品种, 从初版、1.0版、1.1版到目前的2.0版,已经3次升级,不仅内容更加完善、实用,还展现了.NET 2.0的最新技术和ASP.NET 2.0最新编程知识,是各种初学者学习ASP.NET的优秀教程,也是Web开发人员了解ASP.NET 2.0新技术的优秀参考书。该书与《ASP.NET 2.0高级编程(第4版)》及其早期版本,曾影响到无数中国Web程序员。一起来看看 《ASP.NET 2.0入门经典》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

随机密码生成器
随机密码生成器

多种字符组合密码