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>$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>
<?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 );?>
<!-- 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>