有沒有什麼方法可以在默認情況下在php smarty中使用strip_tags,以允許特定的html標籤通過?Php smarty strip_tag允許特定標籤
stip_tags($a.message,'<p><div>');
smarty中的等價物是什麼?
{$a.message|strip_tags}
有沒有什麼方法可以在默認情況下在php smarty中使用strip_tags,以允許特定的html標籤通過?Php smarty strip_tag允許特定標籤
stip_tags($a.message,'<p><div>');
smarty中的等價物是什麼?
{$a.message|strip_tags}
我使用的是Smarty 2.6.26和strip_tags
,它使用指定要保留哪些標記的參數。
試試這個:
PHP:
$string = "<b>not bold</b><iframe>iframe goes away</frame> <p>paragraphed</p>
<div style='color:green'>div kept.</div>";
$smarty->assign('string', $string);
在模板:
{$string|strip_tags:"<p><div>"}
<p>
和<div>
不會被剝離。
根據documentation,不可能指定保留哪些標籤。但是,您可以輕鬆地爲自己創建一個插件: http://www.smarty.net/docs/en/plugins.writing.tpl
我知道我有點晚,但對於那些誰需要做到這一點,不想寫一個Smarty的 - 插件:
在Smarty的你可以從PHP「借」的方法,這樣。
相反的:
{$a.message|strip_tags}
使用
{strip_tags($a.message,"<br><div>") nofilter}
注:你只需要NOFILTER說法,如果你設置$smarty->escape_html = true;
你可以使用regex_replace代替。請參閱:http://www.smarty.net/docsv2/en/language.modifier.regex.replace.tpl – 2012-08-07 06:27:34