html格式存放到mysql,将html格式的文本保存到数据库

在尝试将HTML格式的文本保存到数据库并从数据库中取出编辑时遇到问题,HTML特殊字符如<和>未正确显示。解决方案是使用htmlspecialchars()函数在入库前处理字符串,然后在取出来时使用htmlspecialchars_decode()进行解码。这样可以确保HTML代码在textarea中正常显示并能正确保存回数据库。
摘要由CSDN通过智能技术生成

I want to save html-formatted text to database, but when I do that it is don't save html-symbols like < / > ' and others

This is how I read article from database for editing:

Англійський варіант:

" >

after this generates such html-code:

Англійський варіант:

So, I expect that this text will appear in my text field, in html-code of this page it is, but in text area is no.

In database I save it as:

Hello

So how can I do the follow:

Read from database

html-formattedtext.

Show it in textarea element.

Edit and save it back to database.

Help me please, how can I save such texts properly, Thanx!

解决方案

Try using htmlspecialchars() on the string to put into the DB, and then, when pulling it back out, use htmlspecialchars_decode(). Might make a difference.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值