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://codercto.com/soft/d/12992.html

Web标准设计

Web标准设计

刘杰(嗷嗷) / 清华大学出版社 / 2009-1 / 75.00元

一扇经常开启的门的铰链不需要润滑油。 一条湍急的河流不会变得污浊。 无论是声音还是想法都不可能在真空中传播。 Web标准如果不用就会腐朽。 这世界真奇妙! 专题页面:http://www.aoao.org.cn/book/web-standards-design/一起来看看 《Web标准设计》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码