Function similar to strip_tags

Asked

Viewed 43 times

2

Is there any type of strip_tags that I pass by parameter the elements that I DO NOT allow?

Suppose I have a string "blabkabla<span>bla<span><p>blablabla<p>". I want for example to remove only the <p> and not allow, only the <span>.

  • 1

    Can you give an example of what you have and how you want it to look? Are you talking about HTML? text with tags? difficult to understand...

  • Suppose I have a string "blabkabla<span>bla<span><p>blablabla<p>". I want to remove ONLY <p> and not allow only <span>. It’s just an example.

  • You know what the DOMDocument PHP? I think that’s the way...

  • Where does your string come from? It’s an input?

1 answer

2

I don’t quite understand what you need, you just want to allow span in any case or have rule? Do you still want content within the P? What’s wrong with strip_tags($string, '<span>'), I think it’s more valid for you to say what you allow, no?

To only allow what you want, use

strip_tags($string, '<span><br><qualquertag>')

To create a blocked list use

preg_replace("/<\/?(p|embed|object|frameset|frame|iframe|meta|link|style)[^>]*>/", '', $string)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.