编码到Utf8,我有一些 [英] Encoding To Utf8, I have some ÂÂ

查看:130
本文介绍了编码到Utf8,我有一些的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我有一些字符,像这样等于一个双引号()
i有一些字符,如â??



我想修复它们,但我不知道如何。

由于我使用preg_replace如果我使这个代码

  $ text =这是一个listingTitle与编码问题'; 
$ test = preg_replace(/Ã,Â/,'',$ text);
echo $ test;

$ test仍然会在字符串中出现编码错误,因此它像preg_replace不看到编码问题。



有没有一个想法,我可以做什么来修复那些编码错误?
或者有办法我应该继续



感谢



---------------------------------------------



好,所以现在想做的是将每个字符转换回utf8
由于某种原因我的字符串混合了一些编码..



这里是一个字符串和构成字符串的字符的细分。



Milwaukee 2415-21 M12无绳锂离子3 / 8°直角钻/驾驶套件wi



这是分解

  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] 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] 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] 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] encoding is = ASCII

现在可以做什么?

解决方案

查看 github 中的常见编码的PHP类别编码>



用法:

  $ utf8_string = Encoding :: toUTF8 $ utf8_or_latin1_or_mixed_string); 

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

也:

  $ utf8_string = Encoding :: fixUTF8($ garbled_utf8_string); 

示例:

  echo Encoding :: fixUTF8(Fédicure Camerounaise de Football); 
echo Encoding :: fixUTF8(Fêéd'ation Camerounaise de Football);
echo Encoding :: fixUTF8(FêéédééCamerounaise de Football);
echo Encoding :: fixUTF8(FêÃéédÃÃééCamerounaise de Football);

将输出:

 FédérationCamerounaise de Football 
FédérationCamerounaise de Football
FédérationCamerounaise de Football
FédérationCamerounaise de Football

更新:



检查:(我检查过这个工作)

  $ output ='这是一个listingTitle有编码问题'; 
$ output = preg_replace('/ [^(\x20-\x7F)] * /','',$ output);
echo($ output);

输出:

 code>这是一个带有编码问题的listingTitle。 

输出图片:



>


I realised a couple week ago that we had some weird character on some old listing that i have on our website

i have some character like this  that are equal to a dualquote (") i have some character like â??

I want to repair them but i dont know how.

Since when i use a preg_replace if i make this code

$text = 'this is a listingTitle  with an encoding problem';
$test = preg_replace("/ÂÂ/",'"',$text);
echo$test;

$test will still have that encoding error in the string so it is like the preg_replace dont see the encoding problem.

is there some one that have an idea on what can i do to repair those encoding error ? Or is there a way i should proceeded

Thanks

Edit Here--------------------------------------------------

Ok so what im trying to do now is to convert back each char to utf8 And since for some reason my string are mixed with a few encoding..

So here is a string and a breakdown of the char making the string.

Milwaukee 2415-21 M12 Cordless Lithium-Ion 3/8Â Right Angle Drill/Driver Kit wi

and this is the break down

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

what can i do now?

解决方案

Check This PHP Class Encoding featuring popular Encoding in github

Usage:

$utf8_string = Encoding::toUTF8($utf8_or_latin1_or_mixed_string);

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

also:

$utf8_string = Encoding::fixUTF8($garbled_utf8_string);

Examples:

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");

will output:

Fédération Camerounaise de Football
Fédération Camerounaise de Football
Fédération Camerounaise de Football
Fédération Camerounaise de Football

UPDATE:

Check this :(i checked This Worked)

$output = 'this is a listingTitle  with an encoding problem';
$output = preg_replace('/[^(\x20-\x7F)]*/','', $output);
echo($output);

Output:

this is a listingTitle with an encoding problem.

Output pic:

这篇关于编码到Utf8,我有一些的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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