phpsmartyparagraphstrip-tags

Using Smarty to strip P tags from my HTML


I'm using this code {$entry.entry|strip_tags} to strip tags, however I would just like to strip <p> tags and not all HTML tags.

Can someone help?

Thank you


Solution

  • If you want to strip ONLY <p> tags, try a simple regular-expression replacement:

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

    This will replace <p>, </p> and all <p many attributes> strings with an empty string.

    Let me know if it works. I tested the regular expression in PHP, not directly in Smarty.