Output Filters

PHP Smarty

Smarty - the compiling PHP template engine
Prev 来源:PHP中文社区 Chapter 15. Advanced Features Next

Output Filters

输出滤镜

<?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
?>

Prev Home Next
Postfilters Up Cache Handler Function