Summary of four types of security filtering functions in PHP (with code)

Source: Internet
Author: User
This article introduces you to the content of PHP four security filter function summary (with code), there is a certain reference value, the need for friends can refer to, I hope to help you.

1. Stripslashes () function

Stripslashes () The main function is to remove the backslash

<?phpecho stripslashes ("Who\ 's Bill Gates?");? >

Output Result:

Who ' s Bill Gates?

2. Htmlentities () function

Htmlentities () converts a character to an HTML entity

<?php$str = "<?" W3s?h???? > Echo htmlentities ($str);? >

The HTML output of the above code is as follows (see source code):

<! DOCTYPE html>

The browser output of the above code:

<? W3s?h???? >

3. Htmlspecialchars () function

Convert pre-defined characters "<" (less than) and ">" (greater than) to HTML entities:

<?php$str = "This is some <b>bold</b> text."; echo Htmlspecialchars ($STR);? >

The HTML output of the above code is as follows (see source code):

<! DOCTYPE Html>

The browser output of the above code:

This is some <b>bold</b> text.

4. Strip_tags () function

Peel the HTML tags from the string:

The Strip_tags () function strips the HTML, XML, and PHP tags from the string.

Note: This function always strips HTML comments. This cannot be changed by the Allow parameter.

Note: This function is binary safe.

<?phpecho strip_tags ("Hello <b>world!</b>");? >
Hello world!

Related articles recommended:

PHP Implementation Method Summary (code) for extracting numbers in a string

What is the difference between the Echo statement and the print statement in PHP5

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.