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
PHP provides an inbuilt function to remove the HTML tags from the data. The strip_tags() function is an inbuilt function in PHP that removes the strings form HTML, XML and PHP tags. It accepts two parameters. This function returns a string with all NULL bytes, HTML, and PHP tags stripped from a given $str.
The strip_tags() function strips a string from HTML, XML, and PHP tags. Note: HTML comments are always stripped. This cannot be changed with the allow parameter. Note: This function is binary-safe.
HTML Stripper removes HTML tags and convert HTML code to text, which scrub text formatting of the HTML to save and share TEXT. HTML stripping is the process by which unnecessary HTML tags are removed from a web page. A common use case for this is when someone wants to publish an article on a website they don't control.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With