Character escape problems

Source: Internet
Author: User
Character escape problems such as the string [td] ForGod \ 'ssake! [/Td] I escaped single quotes and saved them to the database. When the article is displayed, it is found that the article contains an escape slash. Without escaping, it is saved directly to the database. sometimes it is wrong to insert data into the database. What should I do? // Escape the conversion of some special characters functionformat_h
Such as string
[Td] God \'sSake! [/Td]
I escaped single quotes and saved them to the database.

When the article is displayed, it is found that the article contains an escape slash.
Without escaping, it is saved directly to the database. sometimes it is wrong to insert data into the database. What should I do?


// Convert some special characters
Function format_html ($ str ){
$ Str = str_replace (',', $ str );
$ Str = str_replace ('"', '"', $ str );
$ Str = str_replace ('·', '·', $ str );
$ Str = str_replace (''', ''', $ str );
$ Str = str_replace (''', ''', $ str );
$ Str = str_replace ('... ','... ', $ Str );
$ Str = str_replace ('-;', '-', $ str );
Return $ str;
}

In addition, does php have built-in functions that can achieve the same effect as my above functions? Because the above conversion is not complete.

------ Solution --------------------
PHP code
$ Str = "For God's sake! "; // When receiving data... insert into tb... col = '". addslashes ($ str ). "'... // echo htmlspecialchars ($ str );
------ Solution --------------------
Mysql_real_escape_string
------ Solution --------------------
Discussion

Mysql_real_escape_string

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.