Using Smarty to strip P tags from my HTML
-
08-12-2019 - |
Pergunta
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
Solução
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.
Outras dicas
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}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow