如何使用php正确解码亚洲字符

时间:2013-03-16 03:34:27

标签: php decode encode

<?php

include('simple_html_dom.php');

$test = file_get_contents('http://translate.google.com/?langpair=en|ja&text=math');
//echo $test;

$URL = "http://translate.google.com/?langpair=en|ja&text=math";
$html = file_get_html($URL);

foreach($html->find('span.short_text') as $e)
echo  $e->innertext;

?>

我正试图从谷歌翻译中刮掉日语汉字并让亚洲字符正确显示,但我遇到了问题。原样,此代码打印“Šw。当我取消注释“echo $ test”时,它会输出正确的字符,即数学(以及之前的一堆其他内容)。我尝试过编码/解码,htmlspecial字符等等。但这些都不起作用。我的第二个问题是,当我手动将数学写入我的计算机的文本文件,并尝试从我的iPhone查看该文本时,它显示奇怪,这很奇怪,因为我知道iPhone可以很好地读取日文字符。我在Chrome上,但知道我在使用Firefox。

我也可以把它输出为:%C3%A6%E2%80%A2%C2%B0%C3%A5%C2%AD%C2%A6

2 个答案:

答案 0 :(得分:1)

您必须更改字符串的编码

mb_convert_encoding ( $str_to_conver , $to_encoding , $from_encoding ] )

将str的字符编码从to_encoding转换为to_encoding。

答案 1 :(得分:0)

这为我显示了编码的亚洲字符...

$url = html_entity_decode($string,ENT_COMPAT,"UTF-8");
相关问题