将来自ISO-8859-1的ajax响应转换为UTF8 [英] converting ajax response from ISO-8859-1 to UTF8
问题描述
我使用Ajax调用来接收希伯来语的响应。结果来自不同的网站,并且 ISO-8859-1
编码。我的页面是 UTF-8
。
回应看起来像西里尔文:
îéãòìîáìáæ÷äçáøäáéùøàìéúàéï
当我尝试使用ajax页面上的标题:
header('Content-Type:text / html; charset = ISO-8859-1');
我得到这个结果:
ÃÃÃÃÃÃÂãòÃÃÃÃÃÃÃÃÃÃÃÃïÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃà éðÃéÃ
utf8_encode
对响应似乎没有帮助。
我应该怎么做才能正确解码?
谢谢!
编辑:
数据具有
ISO-8859-1
的编码,但是查看响应的特定标题中的数据我看到字符集设置为windows-1255
。
现在我做的是将标题设置为:
header('Content-Type:text / html; charset = windows-1255');
在php的一边我添加了
iconv
echo :
echo iconv(WINDOWS-1255,UTF-8,$ response);
解决方案将我的头撞在墙上一段时间后,我决定直截了当并创建了一个工作非常容易的字符映射。
以下是代码:
$ lat = array('à','á','â','ã','ä','å','æ','ç','è','é','ê' ,'ë','ì','í','î','ï','ð','ñ','ò','ó' ÷','ø','ù','ú');
$ heb = array('א','ב','ג','ד','ה','ו','ז','ח','ט','י' ך','כ','ל','ם','מ','ן','נ' ,'ק','ר','ש','ת');
echo str_replace($ lat,$ heb,$ response);
我还发现这些资源很有价值:
http://orwell.ru/test/CP/_?cp1252
http://orwell.ru/test/CP/_?cp1255
和这一个:
http://kanjidict.stc.cx/recode.php
I use an Ajax call to receive a response in hebrew. The results come from a different site and are
ISO-8859-1
encoded. My page isUTF-8
. the response looks like Cyrillic:îéãò ìî÷áì áæ÷ äçáøä äéùøàìéú àéï
when I try to use the header on the ajax page:
header('Content-Type: text/html; charset=ISO-8859-1');
I get this result:
îéãò ìî÷áì áæ÷ äçáøä äéùøà ìéú à éï
utf8_encode
on the response did not seem to help.What should I do to decode correctly ?
Thanks!
Edit:
I did notice right now that the actual page that shows the data has an encoding of
ISO-8859-1
, but looking in the specific header of the response with the data I see the charset is set towindows-1255
.WHat I did now is setting the header to :
header('Content-Type: text/html; charset=windows-1255');
and on the php's side I added
iconv
and simply echo:
echo iconv("WINDOWS-1255","UTF-8",$response);
解决方案After banging my head in the wall for a while, I decided to be straightforward about it and created a mapping for the characters which worked very easily. I couldn't find a solution otherwise.
Here's the code:
$lat = array('à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ','ò','ó','ô','õ','ö','÷','ø','ù','ú'); $heb = array('א','ב','ג','ד','ה','ו','ז','ח','ט','י','ך','כ','ל','ם','מ','ן','נ','ס','ע','ף','פ','ץ','צ','ק','ר','ש','ת'); echo str_replace($lat, $heb, $response);
I also found these resources valuable:
http://orwell.ru/test/CP/_?cp1252 http://orwell.ru/test/CP/_?cp1255
and this one too:
http://kanjidict.stc.cx/recode.php
这篇关于将来自ISO-8859-1的ajax响应转换为UTF8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!