In this tutorial we are going to discuss how to remove all HTML tags from string PHP by using the strip_tags()
The strip_tags() is a function that strips out a string from HTML, XML and PHP tags parameter one. Although we can also use parameter two to define a list of HTML tags we want.
This function can be very helpful in different manners like, if we create our own message box on our site.as we all know that some use abusive language like <h1> THIS SITE SUCKS! </H1>. So, they could use that but they will not do that because by using this function we can display the titles of each post on our board and can also display their unwanted messages in immense letters on an outsider’s screen.
Here are two examples of stripping out tags:
$input = "<blink><strong>Hello!</strong></blink>";
$a = strip_tags($input);
$b = strip_tags($input, "<strong><em>");
After running that script $a will be set to “hello!” and $b will be set to <strong> hello!</strong> because we have “strong” in the list of supportable tags.
By using this technique we can terminate most of the users that are contrarily changing the style of our website. It is still possible for users to create problem.only when you allow a certain list of HTML tags.
For example we could allow the abuse <strong> tag using CSS
<strong style="font: 72pt Times New Roman">THIS SITE SUCKS!</strong>.
We should remember one thing if we allow <strong> tags, we allow all strong tags, anyhow they have any extra unwanted information in there, so it is best not to allow any tag.