Tuesday, June 16, 2026
HomeLanguagesPHP strip_tags() Function

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 a required parameter that specifies the string to be check.
  • $allow: It is an optional parameter that 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:  

PHP




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


Output: 

Hello neveropen!

 

Program 2: 

PHP




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


Output

Hello <b>neveropen!</b>

Related Articles: 

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

RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS