您好,欢迎访问一九零五行业门户网

PHP编码转换减号(连接符)无法转换问题

php编码转换减号(连接符)无法转换问题技术 maybe yes 发表于2015-01-23 16:03
使 用 php 的 iconv 或 mb_convert_encoding 函数进行编码转换,比如将 gb2312 转换为 utf-8 编码,在出现某些特殊字符(减号,连接符)时,不能正常工作,可能会变成问号?或者c。尝试了多种方法,依然不能很好的解决这个问题。如下代码, 在声明了 //ignore 后遇到连接符号-仍然会变成符号?。
按照 php 官网手册中网友提供的解决方法进行尝试,仍然不能解决问题,不知道是不是我本地 php 版本的问题。
解决方法一:
please note that iconv('utf-8', 'ascii//translit', ...) doesn't work properly when locale category lc_ctype is set to c or posix. you must choose another locale otherwise all non-ascii characters will be replaced with question marks. this is at least true with glibc 2.5.
example:
[翻译]
请注意 iconv 在语言环境类别 lc_ctype 类别设置为 c 或者 posix 时不能正常的工作。你必须选择另一个语言,否则所有的非 ascll 编码将被替换成问号?。这个问题在 glibc 2.5 以下是真实的。
举例如下:
解决方法二:
that will strip invalid characters from utf-8 strings (so that you can insert it into a database, etc.). instead of none you can also use the value 32 if you want it to insert spaces in place of the invalid characters.
阅(75)评(0)查看评论
其它类似信息

推荐信息