smarty模板中如何调用PHP自定义函数

registerPlugin函数,该函数的原型为

void registerPlugin(string type,
string name,
mixed callback,
bool cacheable,
mixed cache_attrs);

function htmlcode($paras) {
extract($paras);
Return str_replace('/n/r','<br>',str_replace(' ',' ',$cont));
}
$smarty=new Smarty();
$smarty->registerPlugin('function','format_content','htmlcode');
$smarty->display("list.html");

 

//list.html
<table width="500px" border="0" cellspacing="5" cellpadding="1" bgcolor="#add3ef">
{section name=reply loop=$content}
<tr bgcolor="#eff3ff">
<td>标题:{$content[reply].title} 用户:{$content[reply].user}</td>
</tr>
<tr bgcolor="#ffffff">
<td>内容:{format_content cont=$content[reply].content}</td>
</tr>
{/section}
</table>