php中smarty變量修飾用法實(shí)例分析
本文實(shí)例講述了php中smarty變量修飾用法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
test.php代碼:
<?php
require 'libs/Smarty.class.php'; //包含Smarty類庫文件
$smarty = new Smarty; //創(chuàng)建一個新的Smarty對象
$total = 12345; //對$total賦值
$smarty->assign("total",$total); //對模版中的變量賦值
$formatted_total = number_format($total); //格式化$total
$smarty->assign("formatted_total",$formatted_total); //對模版中的變量賦值
$smarty->display('test1.htm'); //顯示頁面
?>
test1.html模板代碼:
<html>
<head>
<title>Smarty Test</title>
</head>
<body>
<H1>Total is {$total}</H1>
<H1>Formatted Total is {$formatted_total}</H1>
</body>
</html>
編譯后的test.html.php代碼:
<?php /* Smarty version 2.6.22, created on 2009-03-19 14:37:39
compiled from test1.htm */ ?>
<html>
<head>
<title>Smarty Test</title>
</head>
<body>
<H1>Total is <?php echo $this->_tpl_vars['total']; ?>
</H1>
<H1>Formatted Total is <?php echo $this->_tpl_vars['formatted_total']; ?>
</H1>
</body>
</html>
test1.html模板可以改寫成這樣test2.html:
<html>
<head>
<title>Smarty Test</title>
</head>
<body>
<H1>Total is {$total}</H1>
<H1>Formatted Total is {$total|number_format}</H1>
</body>
</html>
則相應(yīng)的test.php代碼改為:
<?php
require 'libs/Smarty.class.php'; //包含Smarty類庫文件
$smarty = new Smarty; //創(chuàng)建一個新的Smarty對象
$total = 12345;
$smarty->assign("total",$total); //對模版中的變量賦值
$smarty->display('test2.htm'); //顯示頁面
?>
瀏覽器顯示:
Total is 12345
Formatted Total is 12,345
希望本文所述對大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
php無限級分類實(shí)現(xiàn)評論及回復(fù)功能
這篇文章主要為大家詳細(xì)介紹了php無限級分類實(shí)現(xiàn)評論及回復(fù)功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-02-02
ThinkPHP頁面跳轉(zhuǎn)success與error方法概述
這篇文章主要介紹了ThinkPHP頁面跳轉(zhuǎn)success與error方法概述,需要的朋友可以參考下2014-06-06
phpstudy后門rce批量利用腳本的實(shí)現(xiàn)
這篇文章主要介紹了phpstudy后門rce批量利用腳本的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
詳解php幾行代碼實(shí)現(xiàn)CSV格式文件輸出
本篇文章主要介紹了詳解php幾行代碼實(shí)現(xiàn)CSV格式文件輸出,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07
Zend Framework框架實(shí)現(xiàn)類似Google搜索分頁效果
這篇文章主要介紹了Zend Framework框架實(shí)現(xiàn)類似Google搜索分頁效果,結(jié)合實(shí)例形式分析了Zend Framework框架實(shí)現(xiàn)分頁效果所涉及的基本查詢、判斷與分頁效果構(gòu)造相關(guān)操作技巧,需要的朋友可以參考下2016-11-11

