2012-08-07 39 views
3

有沒有什麼方法可以在默認情況下在php smarty中使用strip_tags,以允許特定的html標籤通過?Php smarty strip_tag允許特定標籤

stip_tags($a.message,'<p><div>'); 

smarty中的等價物是什麼?

{$a.message|strip_tags} 
+0

你可以使用regex_replace代替。請參閱:http://www.smarty.net/docsv2/en/language.modifier.regex.replace.tpl – 2012-08-07 06:27:34

回答

4

我使用的是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>不會被剝離。

+0

,我有舊版本,我確定我做了,由成員交付,我之前嘗試過的代碼,並沒有工作 – Benn 2012-08-07 06:56:24

+0

es,我的是2.6.2 – Benn 2012-08-07 06:58:32

1

我知道我有點晚,但對於那些誰需要做到這一點,不想寫一個Smarty的 - 插件:

在Smarty的你可以從PHP「借」的方法,這樣。

相反的:

{$a.message|strip_tags} 

使用

{strip_tags($a.message,"<br><div>") nofilter} 

注:你只需要NOFILTER說法,如果你設置$smarty->escape_html = true;