Function for saving html text to mysql database -- mysql_real_escape_string

Source: Internet
Author: User
Tags derick
(PHP4 & gt; 4.3.0, PHP5) mysql_real_escape_string & nbsp; & mdash; & nbsp; escape special characters in strings used in SQL statements, and take into account the connected current character set & nbsp; description: string & nbsp; mysql_real_escape_str

(PHP 4> = 4.3.0, PHP 5)

Mysql_real_escape_string? -? Escape special characters in strings used in SQL statements, and take into account the connected current character set

? Description string? Mysql_real_escape_string? (? String? $unescaped_string? [,? Resource? $link_identifier?] )

This function will?unescaped_string? Can be safely used? Mysql_query ().

Note:?Mysql_real_escape_string ()? Not escape?%? And?_.

Example #1?Mysql_real_escape_string ()? Example

$item?=?"Zak's?and?Derick's?Laptop";
$escaped_item?=?mysql_real_escape_string($item);
printf?("Escaped?string:?%s\n",?$escaped_item);
?>

The above example will generate the following output:

Escaped string: Zak\'s and Derick\'s Laptop

See? Mysql_escape_string ()? And?Mysql_character_set_name ().

Example:

$ Content = mysql_real_escape_string ($ content );

Pass $ content that contains html text into the function. The Returned text string is a string that has been escaped and can be correctly inserted into the database, otherwise, text containing special html characters cannot be directly inserted into the database.

Note: html content can be correctly output without any processing when retrieving data from the database!

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.