如何在MySQL中保存特殊字符 [英] How to save special character in mysql

查看:438
本文介绍了如何在MySQL中保存特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我想问一下我们如何将特殊字符保存到mysql中?情况是我正在使用tinymce做单词编辑器.现在,当我输入某些内容并在该编辑器中添加一些样式时,将其保存在数据库中时,它的工作正常.但是问题是当我键入特殊字符(例如

Hi guys i would like to ask how do we save a special character into mysql? the situation is that i''m using tinymce for word editor. now when i type in something and put some styling in that editor its working fine when i save it in the database base. but the problem is when i type in a special character such as

<  or  > 

)时.当我尝试查看tinymce

. when i try to view the generated word of tinymce

instead of returning < it returns "< ;"

的生成单词以及它应该如何显示时.但是当我尝试执行查询时,特殊字符

and that how it should be. but when i try to execute the query all of the text after the special character

< ;

之后的所有文本都不见了.

我真的不知道该如何保存它...假设tinymce生成了这种内容

are gone.

I really dont know how to save it anymore... Assuming that the tinymce generated this kind of content

<span style="color: #888888;">This is the content generated by tinymce</span> and this is the special character &lt; and a greater than sign &gt;



我希望保存此内容,但问题是& lt;之间的所有字符.和& gt;全部擦除....我该如何保存并同时检索并将其显示在tinymce上?所以我希望它可以显示在tinymce中,就像这样



I wish to save this content but the problem is all the character in between &lt; and &gt; are all erase.... how do i save this and same time retrieve and display it on tinymce? so i would like it to be display in tinymce as this

<span style="color: #888888;">This is the content generated by tinymce</span> and this is the special character < and a greater than sign >

推荐答案

我已经发现了问题...我发现在我的JS文件中,我使用此函数tinyMCE.get("tiny).getContent(),但是问题是当编辑器包含此字符<"时它将其解释为<"然后,当我在Ajax中提交它,而php读取该发布数据时,它会考虑<"作为另一个参数传递...所以我要做的是使用encodeURIComponent(tinyMCE.get("tiny").getContent())并最终解决了问题
I already found the problem... I found out that in my JS file im passing the content of tinymce using this function tinyMCE.get("tiny").getContent() but the problem with this is that when the editor contains this character "<" it interpret it as "<" then when i submit it in ajax when php read that post data it consider the "<" as another parameter pass... so what i did was to use encodeURIComponent(tinyMCE.get("tiny").getContent()) and it finally solve the problem


什么字符集是您使用的是什么?使用Latin1字符集进行插入
What character set are you using? INSERT using Latin1 character set


尝试使用mysql_real_escape_string() ^ ].


这篇关于如何在MySQL中保存特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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