• Register

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.

More Posts

How to remove html tags from string in PHP Tushar Shuvro - May 16, 2020
How to remove underline from hyperlink in html Prasandeep Gautam - Oct 22, 2020
How to show data in drop-down list from database in PHP Tushar Shuvro - Apr 28, 2020
Sort table columns using php by clicking header (asc desc) Tushar Shuvro - Apr 24, 2020
HTML code to send email with attachment kunal verma - Nov 1, 2020
Marquee tag in HTML for multiple images kunal verma - Oct 21, 2020
How to reduce image size in HTML kunal verma - Oct 17, 2020
How to add icon in HTML title kunal verma - Oct 17, 2020
How to fetch data from database in php and display in html form Tushar Shuvro - Apr 18, 2020
How to add image in html from a folder Tushar Shuvro - May 19, 2020