Do php's strip_tag function consider a string with two underlines a constructor?

91 Views Asked by At

I'm using PHP's strip_tag function in a WordPress project, and it works just ok, except when a link that contains two underlines (for example: http://www.youtube.com/watch?v=CS7e1__lyn4) comes in. When the link comes in, it returns empty. Is there a way to tell strip_tag to ignore two underlines?

1

There are 1 best solutions below

0
On

Have you read the documentation?

There's no reason for strip_tags() to break with the two underlines "__" in the text or tag.

A possible fix in your instance (if you want to keep the href) is to set the second parameter to strip_tags() that would allow you to set permitted tags:

$my_string = 'This is a string <a href="http://www.youtube.com/watch?v=CS7e1__lyn4">My Link</a>';

echo strip_tags($my_string, "<a>");

Also make sure that you are indeed sending a valid string to the strip_tags function. This can seem trivial, but people make mistakes.