PHP | strip_tags() Function

The strip_tags() function is an inbuilt function in PHP which is used to strips a string from HTML, and PHP tags. This function returns a string with all NULL bytes, HTML and PHP tags stripped from a given $str.

Syntax:

string strip_tags( $str, $allowable_tags ) 

Parameters: This function accepts two parameters as mentioned above and described below:

  • $string: It is required parameter which specifies the string to be check.
  • $allow: It is an optional parameter which specifies allowable tags. These tags will not be removed.

Return Value: This function Returns the stripped string.

Exceptions:



  • This function strip HTML comments and PHP tags. It can not be used this in $allow tags because this is already hardcoded.
  • PHP 5.3.4 and later versions, ignored the self-closing XHTML tags
  • strip_tags() does not validate the HTML.

Below programs illustrate the strip_tags() function in PHP:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// PHP programme to illustrate 
// strip_function without $allow parameter
echo strip_tags("Hello <b>GeeksforGeeks!</b>");
?>

chevron_right


Output:

Hello GeeksforGeeks!

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// PHP programme to illustrate 
// strip_function with $allow parameter
  
echo strip_tags("Hello <b><i>GeeksorGeeks!</i></b>", "<b>");
?>

chevron_right


Output:

Hello <b>GeeksorGeeks!</b>

Related Articles:

Reference: http://php.net/manual/en/function.strip-tags.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.