Using Smarty to tag P tags from my HTML code

I use this code {$entry.entry|strip_tags} to highlight tags, but I would just separate the <p> tags and not all the HTML tags .

Can anyone help?

thanks

+4
source share
2 answers

If you want to remove ONLY <p> tags, try performing a regular regular expression replacement:

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

This will replace the <p> , </p> lines and all <p many attributes> lines with an empty line.

Let me know if that works. I tested the regex in PHP, not directly in Smarty.

+9
source

You can do this using the regex_replace modifier:

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

Source: https://habr.com/ru/post/1400054/


All Articles