PHP content inserted into the database requires mysql_escape_string to handle the display when using Htmlentities

Source: Internet
Author: User

PHP content into the database needs mysql_escape_string processing

Mysql_escape_string (PHP 4 >= 4.0.3, PHP 5, Note: This method has been deprecated in PHP5.3, not recommended) mysql_escape_string--Escapes a string for mysql_query String mysql_escape_string (string unescaped_string) This function escapes unescaped_string so that it can be used safely for mysql_query (). Note: mysql_escape_string () does not escape% and _. This function andmysql_real_escape_string () is exactly the same, except that mysql_real_escape_string () accepts a connection handle and transfers the string in accordance with the current character set. The mysql_escape_string () does not accept the connection parameters, and regardless of the current character set settings. Example 1. Mysql_escape_string () Example <?php$item = "Zak ' Laptop"; $escaped _item = mysql_escape_string ($item);p rintf ("escaped String:%s\n ", $escaped _item);? > Output: Escaped string:zak\ ' s Laptop use Htmlentities when content is displayedThe Htmlentities () function converts a character to an HTML entity. This means that the data that is taken out does not cause syntax errors because it conflicts with its HTML.

PHP content inserted into the database requires mysql_escape_string to handle the display when using Htmlentities

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.