首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编码到Utf8,我有一些说明,

编码到Utf8,我有一些说明,
EN

Stack Overflow用户
提问于 2013-09-11 23:06:01
回答 2查看 9.4K关注 0票数 1

几周前,我意识到我们网站上的一些旧列表上有一些奇怪的字符

我有一些这样的字符,它们相当于双引号(")我有一些字符,比如ƒ,??

我想把它们修好,但我不知道怎么修。

因为当我使用preg_replace时,如果我编写以下代码

代码语言:javascript
复制
$text = 'this is a listingTitle  with an encoding problem';
$test = preg_replace("/ÂÂ/",'"',$text);
echo$test;

$test仍然会在字符串中包含该编码错误,因此就像preg_replace看不到编码问题一样。

有没有人知道我能做些什么来修复这些编码错误?或者有没有办法让我继续下去

谢谢

编辑#en0#

好的,我现在要做的是将每个字符转换回utf8,因为由于某些原因,我的字符串与一些编码混合在一起。

这是一个字符串和组成该字符串的字符的细目。

密尔沃基2415-21 M12无绳锂-离子3/8直角钻头/驱动器套件,带

这是详细的分析

代码语言:javascript
复制
atChar[0] = 'M' encoding is = ASCII
atChar[1] = 'i' encoding is = ASCII
atChar[2] = 'l' encoding is = ASCII
atChar[3] = 'w' encoding is = ASCII
atChar[4] = 'a' encoding is = ASCII
atChar[5] = 'u' encoding is = ASCII
atChar[6] = 'k' encoding is = ASCII
atChar[7] = 'e' encoding is = ASCII
atChar[8] = 'e' encoding is = ASCII
atChar[9] = ' ' encoding is = ASCII
atChar[10] = '2' encoding is = ASCII
atChar[11] = '4' encoding is = ASCII
atChar[12] = '1' encoding is = ASCII
atChar[13] = '5' encoding is = ASCII
atChar[14] = '-' encoding is = ASCII
atChar[15] = '2' encoding is = ASCII
atChar[16] = '1' encoding is = ASCII
atChar[17] = ' ' encoding is = ASCII
atChar[18] = 'M' encoding is = ASCII
atChar[19] = '1' encoding is = ASCII
atChar[20] = '2' encoding is = ASCII
atChar[21] = ' ' encoding is = ASCII
atChar[22] = 'C' encoding is = ASCII
atChar[23] = 'o' encoding is = ASCII
atChar[24] = 'r' encoding is = ASCII
atChar[25] = 'd' encoding is = ASCII
atChar[26] = 'l' encoding is = ASCII
atChar[27] = 'e' encoding is = ASCII
atChar[28] = 's' encoding is = ASCII
atChar[29] = 's' encoding is = ASCII
atChar[30] = ' ' encoding is = ASCII
atChar[31] = 'L' encoding is = ASCII
atChar[32] = 'i' encoding is = ASCII
atChar[33] = 't' encoding is = ASCII
atChar[34] = 'h' encoding is = ASCII
atChar[35] = 'i' encoding is = ASCII
atChar[36] = 'u' encoding is = ASCII
atChar[37] = 'm' encoding is = ASCII
atChar[38] = '-' encoding is = ASCII
atChar[39] = 'I' encoding is = ASCII
atChar[40] = 'o' encoding is = ASCII
atChar[41] = 'n' encoding is = ASCII
atChar[42] = ' ' encoding is = ASCII
atChar[43] = '3' encoding is = ASCII
atChar[44] = '/' encoding is = ASCII
atChar[45] = '8' encoding is = ASCII
atChar[46] = 'Â' encoding is = UTF-8
atChar[47] = '' encoding is = 
atChar[48] = ' ' encoding is = ASCII
atChar[49] = 'R' encoding is = ASCII
atChar[50] = 'i' encoding is = ASCII
atChar[51] = 'g' encoding is = ASCII
atChar[52] = 'h' encoding is = ASCII
atChar[53] = 't' encoding is = ASCII
atChar[54] = ' ' encoding is = ASCII
atChar[55] = 'A' encoding is = ASCII
atChar[56] = 'n' encoding is = ASCII
atChar[57] = 'g' encoding is = ASCII
atChar[58] = 'l' encoding is = ASCII
atChar[59] = 'e' encoding is = ASCII
atChar[60] = ' ' encoding is = ASCII
atChar[61] = 'D' encoding is = ASCII
atChar[62] = 'r' encoding is = ASCII
atChar[63] = 'i' encoding is = ASCII
atChar[64] = 'l' encoding is = ASCII
atChar[65] = 'l' encoding is = ASCII
atChar[66] = '/' encoding is = ASCII
atChar[67] = 'D' encoding is = ASCII
atChar[68] = 'r' encoding is = ASCII
atChar[69] = 'i' encoding is = ASCII
atChar[70] = 'v' encoding is = ASCII
atChar[71] = 'e' encoding is = ASCII
atChar[72] = 'r' encoding is = ASCII
atChar[73] = ' ' encoding is = ASCII
atChar[74] = 'K' encoding is = ASCII
atChar[75] = 'i' encoding is = ASCII
atChar[76] = 't' encoding is = ASCII
atChar[77] = ' ' encoding is = ASCII
atChar[78] = 'w' encoding is = ASCII

我现在能做什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-09-11 23:20:23

查看github中流行编码的PHP Class Encoding

用法:

代码语言:javascript
复制
$utf8_string = Encoding::toUTF8($utf8_or_latin1_or_mixed_string);

$latin1_string = Encoding::toLatin1($utf8_or_latin1_or_mixed_string);

另外:

代码语言:javascript
复制
$utf8_string = Encoding::fixUTF8($garbled_utf8_string);

示例:

代码语言:javascript
复制
echo Encoding::fixUTF8("Fédération Camerounaise de Football");
echo Encoding::fixUTF8("FÃédÃération Camerounaise de Football");
echo Encoding::fixUTF8("FÃÃédÃÃération Camerounaise de Football");
echo Encoding::fixUTF8("FÃÃÃédÃÃÃération Camerounaise de Football");

将输出:

代码语言:javascript
复制
Fédération Camerounaise de Football
Fédération Camerounaise de Football
Fédération Camerounaise de Football
Fédération Camerounaise de Football

更新:

检查这个:(我检查这个工作正常)

代码语言:javascript
复制
$output = 'this is a listingTitle  with an encoding problem';
$output = preg_replace('/[^(\x20-\x7F)]*/','', $output);
echo($output);

输出:

代码语言:javascript
复制
this is a listingTitle with an encoding problem.

输出图片:

票数 10
EN

Stack Overflow用户

发布于 2013-09-11 23:13:33

早些时候,我在从多种语言的xml提要中获取数据时也遇到过同样的问题。

经过一番努力,我找到了一个解决方案,那就是一切都用utf8编码。

1)数据库联合和字符集。

2)数据库连接。

3) html页面类型。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18744840

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档