Using Smarty to strip P tags from my HTML

michaelmcgurk picture michaelmcgurk · Mar 6, 2012 · Viewed 8.1k times · Source

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

Answer

lorenzo-s picture lorenzo-s · Mar 6, 2012

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.