鍍金池/ 教程/ PHP/ Smarty輸出濾鏡
Smarty安裝
Smarty insert
Smarty 建立緩存
Smarty調(diào)試控制臺
Smarty if,elseif,else
Smarty include_php
Smarty多個緩存
Smarty方法
Smarty section,sectionelse
Smarty注釋代碼
Smarty屬性
Smarty緩沖處理函數(shù)
Smarty變量調(diào)節(jié)器
Smarty函數(shù)
Smarty組合修改器
Smarty雙引號里值的嵌入
Smarty預(yù)過濾器
Smarty foreach,foreachelse
Smarty include
Smarty Caching緩存
Smarty變量
Smarty assign用法
Smarty控制插件輸出緩沖
Smarty從配置文件讀取的變量
Smarty對象
Smarty literal
Smarty緩存集合
Smarty教程
Smarty display方法
Smarty自定義函數(shù)
Smarty配置文件
Smarty擴展設(shè)置
Smarty數(shù)學(xué)運算
Smarty輸出濾鏡
Smarty fetch方法

Smarty輸出濾鏡

Output Filters

輸出濾鏡

 

當(dāng)模板通過函數(shù) display() 或者 fetch()被調(diào)用時,它的輸出能夠通過一個或者多個濾鏡而發(fā)出。 它與預(yù)過濾器的不同之處就是預(yù)過濾器編譯模板是在模板保存到磁盤之前,輸出濾鏡是在它執(zhí)行的時候才操作模板輸出的。

Output filters can be either registered or loaded from the plugins directory by using load_filter() function or by setting $autoload_filters variable. Smarty will pass the template output as the first argument, and expect the function to return the result of the processing.

輸出濾鏡同樣能夠通過 load filter() 函數(shù)和設(shè)置 $autoload filters 變量來注冊或者從工具目錄里載入。SMARTY將傳遞模板輸出作為第一個參數(shù),通過自定義函數(shù)返回處理結(jié)果。


Example 15-4. using a template outputfilter -http://www.yiibai.com/smarty

<?php
// put this in your application
function protect_email($tpl_output, &$smarty)
{
 $tpl_output =
 preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!',
 '$1%40$2', $tpl_output);
 return $tpl_output;
}

// register the outputfilter  $smarty->register_outputfilter("protect_email");
$smarty->display("index.tpl");

// now any occurrence of an email address in the template output will have
// a simple protection against spambots
?>


上一篇:Smarty緩存集合下一篇:Smarty安裝