将html格式的文本保存到数据库 [英] save html-formatted text to database
问题描述
我想将html格式的文本保存到数据库,但是当我这样做时,不会保存像< />'和其他
这是我从数据库中阅读文章进行编辑的方式:
< p class =标题>Англійськийваріант:< / p>
< textarea name =ENcols =90rows =20value =<?php echo htmlentities($ articleArr ['EN'],ENT_QUOTES,UTF-8);? >中>< / textarea的>
在生成这样的html代码之后:
< p class =Title>Англійськийваріант:< / p>
所以,我希望这个文本会出现在我的文本字段中,在这个页面的html代码中
在数据库中,我把它保存为:
< p class =Title>你好< / p>
那么我该怎么做:
- 从数据库中读取
html-formattedtext。 - 在textarea元素中显示。
- 将它保存回数据库。
请帮助我,我该如何妥善保存这些文本,Thanx!
htmlspecialchars()
将字符串放入数据库,然后,当它退出,使用 htmlspecialchars_decode()
。可能会有所作为。 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>
after this generates such html-code:
<p class="Title">Англійський варіант:</p>
<textarea name="EN" cols="90" rows="20" value="<p class='Title'> привыт </p>" ></textarea>
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>
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.
这篇关于将html格式的文本保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!