PHP速学教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
本文实例讲述了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程序设计有所帮助。
php免费学习视频:立即学习
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!
已抢6847个
抢已抢91883个
抢已抢14438个
抢已抢50710个
抢已抢190966个
抢已抢86409个
抢