AI编程助手
AI免费问答

php中smarty变量修饰用法实例分析,smarty实例分析_PHP教程

  2016-07-13 09:50   1014浏览 原创

php中smarty变量修饰用法实例分析,smarty实例分析

本文实例讲述了php中smarty变量修饰用法。分享给大家供大家参考。具体实现方法如下:

test.php代码:

assign("total",$total); //对模版中的变量赋值 
$formatted_total = number_format($total); //格式化$total 
$smarty->assign("formatted_total",$formatted_total); //对模版中的变量赋值
$smarty->display('test1.htm'); //显示页面 
?>

test1.html模板代码:

 
   
    <title>Smarty Test</title><h1>Total is {$total}</h1> 
    <h1>Formatted Total is {$formatted_total}</h1> 
   
 

编译后的test.html.php代码:

 
 
   
    <title>Smarty Test</title><h1>Total is _tpl_vars['total']; ?> 
</h1> 
    <h1>Formatted Total is _tpl_vars['formatted_total']; ?> 
</h1> 
   
 

test1.html模板可以改写成这样test2.html:

 
   
    <title>Smarty Test</title><h1>Total is {$total}</h1> 
    <h1>Formatted Total is {$total|number_format}</h1> 
   
 

则相应的test.php代码改为:

assign("total",$total); //对模版中的变量赋值 
$smarty->display('test2.htm'); //显示页面 
?> 

浏览器显示:

Total is 12345
Formatted Total is 12,345

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1015433.htmlTechArticlephp中smarty变量修饰用法实例分析,smarty实例分析 本文实例讲述了php中smarty变量修饰用法。分享给大家供大家参考。具体实现方法如下: t...

php免费学习视频:立即学习
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。