【问题标题】:Php smarty strip_tag allow specific tagsphp smarty strip_tag 允许特定标签
【发布时间】:2012-08-07 06:22:33
【问题描述】:

有什么方法可以像默认一样在 php smarty 中使用 strip_tags 来允许特定的 html 标签通过?

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

smarty 中的等价物是什么?

{$a.message|strip_tags}

【问题讨论】:

标签: php smarty


【解决方案1】:

我正在使用 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:"&lt;p&gt;&lt;div&gt;"}

&lt;p&gt;&lt;div&gt; 不会被剥离。

【讨论】:

【解决方案2】:

我知道我有点晚了,但是对于那些需要这样做并且不想编写 Smarty 插件的人:

在 Smarty 中,您可以像这样从 PHP 中“借用”方法。

代替:

{$a.message|strip_tags}

使用

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

注意:如果你设置了$smarty-&gt;escape_html = true;

,你只需要nofilter参数

【讨论】:

    【解决方案3】:

    根据documentation,无法指定保留哪些标签。但是,您可以轻松地为自己创建一个插件: http://www.smarty.net/docs/en/plugins.writing.tpl

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多