JS 和 PHP 中的特殊字符转义
我的应用程序从输入字段获取文本,然后通过ajax将其发布到php文件以将其保存到db。
var title = encodeURIComponent($('#title').val());
如果我 escape() 标题,一切都可以,但我有“+”字符的问题。所以我使用encodeURIComponent()。
现在我遇到了德国特殊字符的问题,例如“ö”“䔓ü”,它们将像密码一样显示......
知道如何解决这个问题吗?
谢谢
my application geting Text from a input field an post it over ajax to a php file for saving it to db.
var title = encodeURIComponent($('#title').val());
if I escape() the title it is all OK but i have Problems with "+" character. So i use the encodeURIComponent().
Now i habe a Problem with german special characters like "ö" "ä" "ü" they will be displayed like a crypdet something....
Have some an idea how can i solve this problem?
Thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想这与编码有关:您的 HTML 页面可能使用 UTF-8,并且特殊字符的编码如下:
当您的 PHP 页面收到此内容时,它必须知道它是 UTF-8,并将其作为 UTF 处理-8 -- 这意味着服务器端的所有内容都必须使用 UTF-8 :
例如,如果您在 PHP 端使用
var_dump()
来显示从客户端发送的内容,请不要忘记指示生成的页面采用 UTF-8 格式,如下所示:否则,浏览器将使用它的默认字符集——这不一定正确,并且可能显示垃圾。
I suppose this has to do with encoding : your HTML page might be using UTF-8, and the special characters are encoded like this :
When your PHP page receives this, it has to know it's UTF-8, and deal with it as UTF-8 -- which means that everything on the server-side has to work with UTF-8 :
For instance, if you are using
var_dump()
on the PHP side to display what's been sent from the client, don't forget to indicate that the generated page is in UTF-8, with something like this :Else, the browser will use it's default charset -- which is not necessarily the right one, and possibly display garbage.
你可以使用
escape("Abcäüö")
,你会得到“Abc%C4%FC%F6”,然后在php中你可以使用
urldecode($myValue)
得到“ Abcüö 再次You might use
escape("AbcÄüö")
and you would get "Abc%C4%FC%F6"In php you could then use
urldecode($myValue)
to get "AbcÄüö" again