【问题标题】:Using Smarty to strip P tags from my HTML使用 Smarty 从我的 HTML 中去除 P 标签
【发布时间】:2012-03-24 04:35:54
【问题描述】:

我正在使用此代码 {$entry.entry|strip_tags} 去除标签,但我只想去除 <p> 标签和不是所有 HTML 标签

有人可以帮忙吗?

谢谢

【问题讨论】:

    标签: php smarty paragraph strip-tags


    【解决方案1】:

    如果你想去掉 ONLY <p> 标签,试试简单的正则表达式替换:

    {$entry.entry|regex_replace:"/(<p>|<p [^>]*>|<\\/p>)/":""}
    

    这会将&lt;p&gt;&lt;/p&gt; 和所有&lt;p many attributes&gt; 字符串替换为空字符串。

    让我知道它是否有效。我在 PHP 中测试了正则表达式,而不是直接在 Smarty 中。

    【讨论】:

      【解决方案2】:

      您可以使用regex_replace 修饰符来做到这一点:

      {$foo = '<p>hello world</p><p some-att="ribute">foo</p>'}
      {$foo|regex_replace:'#<\s*/?\s*p(\s[^>]*)?>#i':' '|escape}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-30
        • 1970-01-01
        • 2014-06-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多