如何使用PHP将html插入数据库 [英] How to insert html into database using PHP
问题描述
我有以下HTML代码:
< div class =modalid =indexModal>
< span class =thing>< / span>
< a href =#class =closeMetitle =Inchide>&#238; nchide< / a>
< h2 class =title>促销&#355; ia lunii februarie!< / h2>
< div>
< h3> Beneficia&#355; i de promo&#355; ia sezonului。< / h3>
< p>&#206; n luna Februarie,v&#259; ofer&#259; posibilitatea de a achizi&#355; ioana,solarii profesionale&#351; i hobby,sisteme de irigatii,fola&#351; i accesorii cu o reductionre de 10%aplicat&#259; < / p>
< a href =http://www.domain.com/solarii/10/solarii-profesionale-latimi-6m-sau-8mclass =orangeButton> vede&#355; i oferta特殊&#259;!< / a>
< / div>
< / div>
,我想将其插入数据库,但不会保存完整的内容。我试图在插入时使用htmlentities(),当我想显示html时,使用html_entity_decode()。但我得到的是这样:
< div class =modalid =indexModal>
< span class =thing>< / span>
< a href =#class =closeMetitle =Inchide>închide< / a>
<你可以解释一下,如何安全地在数据库中插入一些html,没有问题,以及如何显示html之后在页面上?我的表是utf8_general_ci字符集。解决方案您需要更改数据库结构以接受更多字符。示例:将列类型设置为varchar 250(或者您需要的许多字符)*尽管它具有最大字符数。
I have the following html code:
<div class=" modal" id="indexModal">
<span class="thing"></span>
<a href="#" class="closeMe" title="Inchide">închide</a>
<h2 class="title">Promoţia lunii februarie!</h2>
<div>
<h3>Beneficiaţi de promoţia sezonului.</h3>
<p>În luna Februarie, vă oferă posibilitatea de a achiziţioana, solarii profesionale şi hobby, sisteme de irigatii, folie şi accesorii cu o reducere de 10% aplicată la preţul de producator.</p>
<a href="http://www.domain.com/solarii/10/solarii-profesionale-latimi-6m-sau-8m" class="orangeButton">vedeţi oferta specială!</a>
</div>
</div>
and I want to insert it into database but it doesn't saves the full content. I tried using htmlentities() on insert, and html_entity_decode() when I want to display the html. But all I get is this:
<div class=" modal" id="indexModal">
<span class="thing"></span>
<a href="#" class="closeMe" title="Inchide">închide</a>
<
Can you explain me, how to safely insert some html in database without problems and how to display that html afterwards on a page? My table is utf8_general_ci charset.
解决方案 You need to change your database structure to accept more characters. Example: Set your column type to varchar 250 (or however many characters you need) *it does have a maximum number of characters though.
这篇关于如何使用PHP将html插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!