国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php中smarty變量修飾用法實例分析

2024-05-04 23:36:09
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了php中smarty變量修飾用法,實例分析了smarty模板變量修飾的常用技巧,需要的朋友可以參考下

本文實例講述了php中smarty變量修飾用法。分享給大家供大家參考。具體實現方法如下:

test.php代碼:

 

 
  1. <?php  
  2. require 'libs/Smarty.class.php'//包含Smarty類庫文件  
  3. $smarty = new Smarty; //創建一個新的Smarty對象  
  4. $total = 12345; //對$total賦值  
  5. $smarty->assign("total",$total); //對模版中的變量賦值  
  6. $formatted_total = number_format($total); //格式化$total  
  7. $smarty->assign("formatted_total",$formatted_total); //對模版中的變量賦值 
  8. $smarty->display('test1.htm'); //顯示頁面  
  9. ?> 

test1.html模板代碼:

 

 
  1. <html>  
  2. <head>  
  3. <title>Smarty Test</title>  
  4. </head>  
  5. <body>  
  6. <H1>Total is {$total}</H1>  
  7. <H1>Formatted Total is {$formatted_total}</H1>  
  8. </body>  
  9. </html>  

編譯后的test.html.php代碼:

 

 
  1. <?php /* Smarty version 2.6.22, created on 2009-03-19 14:37:39  
  2. compiled from test1.htm */ ?>  
  3. <html>  
  4. <head>  
  5. <title>Smarty Test</title>  
  6. </head>  
  7. <body>  
  8. <H1>Total is <?php echo $this->_tpl_vars['total']; ?>  
  9. </H1>  
  10. <H1>Formatted Total is <?php echo $this->_tpl_vars['formatted_total']; ?>  
  11. </H1>  
  12. </body>  
  13. </html>  

test1.html模板可以改寫成這樣test2.html:

 

 
  1. <html>  
  2. <head>  
  3. <title>Smarty Test</title>  
  4. </head>  
  5. <body>  
  6. <H1>Total is {$total}</H1>  
  7. <H1>Formatted Total is {$total|number_format}</H1>  
  8. </body>  
  9. </html>  

則相應的test.php代碼改為:

 

 
  1. <?php  
  2. require 'libs/Smarty.class.php'//包含Smarty類庫文件 
  3. $smarty = new Smarty; //創建一個新的Smarty對象  
  4. $total = 12345;  
  5. $smarty->assign("total",$total); //對模版中的變量賦值  
  6. $smarty->display('test2.htm'); //顯示頁面  
  7. ?>  

瀏覽器顯示:

Total is 12345

Formatted Total is 12,345

希望本文所述對大家的php程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿图什市| 安宁市| 上饶市| 阿拉善右旗| 呈贡县| 蚌埠市| 廉江市| 故城县| 浑源县| 河北省| 桃园县| 高阳县| 镇赉县| 清丰县| 三明市| 都匀市| 莒南县| 尉氏县| 通道| 兴国县| 梓潼县| 西丰县| 界首市| 资溪县| 桂林市| 抚顺市| 大安市| 唐山市| 朝阳区| 西盟| SHOW| 青州市| 佛坪县| 霍林郭勒市| 金湖县| 秦皇岛市| 长乐市| 庆安县| 集贤县| 双城市| 杭州市|