This article introduces to you a summary of the four security filtering functions in PHP (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Stripslashes() function
The main function of stripslashes() is to delete backslashes
<?php echo stripslashes("Who\'s Bill Gates?"); ?>
Output result:
Who's Bill Gates?
2. htmlentities() function
htmlentities() converts characters into HTML entities
<?php $str = "<? W3S?h????>"; echo htmlentities($str); ?>
The HTML output of the above code is as follows (view source code):
<!DOCTYPE html> <html> <body> <© W3Sçh°°¦§> </body> </html>
Browser output of the above code:
<? W3S?h????>
3, htmlspecialchars() function
Convert the predefined characters "<" (less than) and " >" (greater than) converted to HTML entity:
<?php $str = "This is some <b>bold</b> text."; echo htmlspecialchars($str); ?>
The HTML output of the above code is as follows (view source code):
<!DOCTYPE html> <html> <body> This is some <b>bold</b> text. </body> </html>
The browser output of the above code:
This is some <b>bold</b> text.
4. strip_tags() function
Strips the HTML tags in the string:
strip_tags() function strips the HTML, XML and PHP in the string Label.
Comments: This function always strips HTML comments. This cannot be changed via the allow parameter.
Note: This function is binary safe.
<?php echo strip_tags("Hello <b>world!</b>"); ?>
Hello world!
Recommended related articles:
Summary of methods for extracting numbers from strings in php (code)
echo statement in PHP5 and What is the difference between print statements
The above is the detailed content of Summary of four security filtering functions in PHP (with code). For more information, please follow other related articles on the PHP Chinese website!