我有一个WYSIWYG编辑器,该编辑器在键入自己的文字时可以很好地工作,但是如果我从某网站复制粘贴,则源代码也将与其一起复制,除非此举会破坏我的代码,否则我希望这样做。 >
在输入字段中,我回显数据,以便可以对其进行编辑并保存到数据库中。
赞:
<input type="hidden" name="content" value="'.$getversion['content'].'">
这就像我在键入自己时所说的那样很好。
但是,例如,如果我从网站复制了一些lorem ipsum文本,它就会复制样式(字体大小,颜色等)。
这样保存:
<p style="margin: 0px 0px 15px; padding: 0px; text-align: justify; font-family: 'Open Sans', Arial, sans-serif;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis libero erat, tincidunt id placerat vel, vehicula at mauris. Morbi nibh sapien, lacinia ultricies urna dapibus, placerat suscipit risus. Maecenas vulputate, ante at blandit aliquam, ante arcu sollicitudin diam, vitae commodo metus mi nec purus. Nullam a cursus justo, eget venenatis dolor. Etiam condimentum a lectus nec volutpat. Ut sodales vestibulum urna, sed eleifend est. Praesent diam nisl, fermentum a orci ac, viverra efficitur dui. Nam eget nulla ante. Suspendisse feugiat tortor non egestas sodales. Morbi id vestibulum nisl. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</p>
<p style="margin: 0px 0px 15px; padding: 0px; text-align: justify; font-family: 'Open Sans', Arial, sans-serif;">Mauris placerat rhoncus metus eu accumsan. Nulla porta tempor tincidunt. Aliquam commodo massa ac ullamcorper ullamcorper. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Cras at ante consectetur, dictum metus auctor, viverra lectus. Mauris tincidunt libero nunc, eu mattis quam rhoncus in. Curabitur ut purus diam. Maecenas posuere elit eget consectetur consequat. Quisque vulputate a magna ac finibus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas ligula nisi, faucibus sed sodales eu, bibendum eu est. Integer blandit velit eget dui fermentum euismod. Maecenas finibus aliquet sem at auctor.</p>
如您所见,它由于引号而中断:
我该怎么办?
我读到在回显它时必须再次使用real_escape_string(我已经在保存时使用它了),但这并不能解决问题。
我还应该提到我用ajax发布它。
答案 0 :(得分:-1)
保存到数据库时,请执行此操作...
htmlentities($str);
从数据库中回显时,执行此操作...
echo html_entity_decode($str);