将 html 格式的文本保存到数据库 [英] save html-formatted text to database

查看:26
本文介绍了将 html 格式的文本保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 html 格式的文本保存到数据库中,但是当我这样做时,不要保存像 < 这样的 html 符号./> ' 等这是我从数据库中读取文章进行编辑的方式:

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:

<p class="Title">Англійський варіант:</p>
    <textarea name="EN" cols="90" rows="20" value="<?php echo htmlentities($articleArr['EN'], ENT_QUOTES, "UTF-8"); ?>" ></textarea>

之后生成这样的html代码:

after this generates such html-code:

<p class="Title">Англійський варіант:</p>
    <textarea name="EN" cols="90" rows="20" value="&lt;p class=&#039;Title&#039;&gt; привыт &lt;/p&gt;" ></textarea>

所以,我希望这个文本会出现在我的文本字段中,在这个页面的 html 代码中是,但在文本区域中不是.

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:

<p class="Title"> Hello </p>

那么我该怎么做:

  1. 从数据库读取html 格式的文本.
  2. 在 textarea 元素中显示.
  3. 编辑并将其保存回数据库.

请帮帮我,我怎样才能正确保存这样的文本,谢谢!

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

推荐答案

尝试在字符串上使用 htmlspecialchars() 将其放入数据库中,然后在将其拉回时使用 htmlspecialchars_decode().可能会有所作为.

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.

这篇关于将 html 格式的文本保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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