简体   繁体   English

使用PHP替换字符串中的所有特殊字符

[英]Replace all special characters from a string using PHP

I am using jQuery editor with PHP it works fine for plane text (text with out special characters) but if I try to post text which contain special characters then it does not store these special characters in to db table.. and when I tried to replace any special character with HTML codes it works fine. 我在PHP上使用jQuery编辑器,它对平面文本(不包含特殊字符的文本)工作正常,但是如果我尝试发布包含特殊字符的文本,则它不会将这些特殊字符存储到db表中。用HTML代码替换任何特殊字符,效果很好。 But it is too difficult to replace all special character one by one.. Is there any script which replace all special characters from a string...? 但是,很难一一替换所有特殊字符。.是否有脚本可以替换字符串中的所有特殊字符...?

Do you mean something like PHP's str_replace()? 您是说类似PHP的str_replace()吗?
http://php.net/manual/en/function.str-replace.php http://php.net/manual/zh/function.str-replace.php

Is there any script which replace all special characters from a string...? 是否有任何脚本可以替换字符串中的所有特殊字符...?

This is the wrong approach. 这是错误的方法。 You need to get your character sets right, so will be no need to replace anything. 您需要正确设置字符集,因此无需替换任何内容。

I don't know what you're doing, but if you are transmitting data through Ajax, it is probably UTF-8 encoded. 我不知道您在做什么,但是如果您通过Ajax传输数据,则可能是UTF-8编码的。 If your database is in a different character set, you may need to convert it. 如果您的数据库使用其他字符集,则可能需要对其进行转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM