如何在数据库中保存和回显符号间的数据


How to save and echo symbol-to-symbol data in database

我有一个简单的表单textarea例如:

<textarea name="script"></textarea>

从这个形式,我试图在MYSQL数据库中保存数据。但是有一个javascript数据。是的,我试着在数据库中保存完整的脚本,然后在页面上回声。所以,我有很多特殊的字符,引号,斜杠等。

例如:

replace(/"/g,"&quot;");

当第一次在DB中添加脚本时-都很好,但是当我编辑它时,&quot"中转换。

是否有办法保存和编辑这样的数据保持每个字符?


更新:如何通过POST发送?:

<textarea name="script">&quot;</textarea>

使用htmlentities() &html_entity_decode() for storage in database.

$orig = "I'll '"walk'" the <b>dog</b> now";
$a = htmlentities($orig);
$b = html_entity_decode($a);
echo $a; // I'll "walk" the &lt;b&gt;dog&lt;/b&gt; now
echo $b; // I'll "walk" the <b>dog</b> now