How to store html code in php + mysql to the database-php Tutorial

Source: Internet
Author: User
Php + mysql how to store html code to the database? Php & nbsp; + & nbsp; mysql & nbsp; how to store html code to the database? What should I pay attention? What type is used for database fields? How does php handle html code? & Lt ;? Php & nbsp; $ html_code & lt; div & nbsp; & gt; & lt; p & gt; hello & nbsp php + mysql how to store html code to the database?
Php + mysql how to store html code to the database?
What should I pay attention? What type is used for database fields? How does php handle html code?
 $ Html_code ='

Hello world

';

// Database table
Part_name | html_code
Hello | ??
?>


------ Solution --------------------
Tinytext can contain a maximum of 255 (2 ^ 8-1) characters.
Text can contain a maximum of 65535 (2 ^ 16-1) characters.
Mediumtext can contain a maximum of 16777215 (2 ^ 24-1) characters.
Longtext can contain a maximum of 4294967295 (2 ^ 32-1) characters.

Select based on situation
------ Solution --------------------
There are two positive solutions upstairs,
Supplement:
1. Save the new string to the database.
2. the field must be of the string type, including text and varchar (the length must be sufficient.
3. when you read data from the database, remember to use the htmlspecialchars function for processing. Otherwise, the received string will be html code.

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.