如何使用PHP将html插入数据库 [英] How to insert html into database using PHP

查看:133
本文介绍了如何使用PHP将html插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下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">&#238;nchide</a>
    <h2 class="title">Promo&#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, folie &#351;i accesorii  cu o reducere de 10% aplicat&#259; la pre&#355;ul de producator.</p>
        <a href="http://www.domain.com/solarii/10/solarii-profesionale-latimi-6m-sau-8m" class="orangeButton">vede&#355;i oferta special&#259;!</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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆