PHP function strip_tags/htmlspecialchars

Source: Internet
Author: User
PHP function strip_tagshtmlspecialchars function: strip_tags ($ str, $ allow)

Purpose: remove html/xml and php labels.

Parameter: $ allow specifies the exceptional tags, which are not deleted.

 World!"); // Output: Hello world! Echo strip_tags ("HelloWorld!",""); // Output: Hello world! // View the html source code: HelloWorld!?>

Note: The fgetss () function has similar functions.

Function: htmlspecialchars (string, quotestyle, character-set)

Purpose: Convert Special characters into html objects.

Note: The conversion special characters include (only these five characters are supported ):

& (And) &
"(Double quotation marks)"
<(Less than) to <
> (Greater than) to>
''(Single quotes)'

  

Function: htmlentities

Purpose: convert all characters into html objects.

Parameter: character-set can specify the character set. if the converted string contains Chinese characters, you must set the character set to GB2312.

Otherwise, garbled characters will appear in the conversion result.


Function: html_entity_decode

Purpose: restores an html object to a character, which is an inverse function of htmlentities.

Function: htmlspecialchars_decode

Function: restores a predefined html object to a character. it is an inverse function of htmlspecialchars.

Function: addslashes

Purpose: add a backslash before a predefined character.

Note: predefined characters include single quotation marks ('), double quotation marks (''), backslash (\), and NULL.

This function is used to prepare suitable strings for strings stored in the database and database query statements.
If the magic_quotes_gpc parameter of php is on and addslashes is automatically run for all get/post/cookie data, do not use addslashes to avoid double-layer escape;

In this case, use the get_magic_quotes_gpc () function for detection.

Function: stripslashes

Purpose: delete the backslash added by the addslashes () function.

Note: This function is used to clear data retrieved from a database or HTML form.


Function: mysql_real_escape_string

Purpose: Escape special characters in strings used in SQL statements.

The affected characters include:

\ X00 \ n \ r \ '"\ x1a

Return: The escaped string is returned successfully. if the string fails, false is returned.

Note: the difference between this function and htmlspecialchars is that mysql_real_escape_string is used to prevent SQL injection,

Htmlspecialchars converts html to avoid XSS attacks.

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.