繁体   English   中英

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

[英]How can I decode Asian characters correctly using php

<?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;

?>

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

我也可以将其输出为以下字符:%C3%A6%E2%80%A2%C2%B0%C3%A5%C2%AD%C2%A6

您必须更改字符串的编码

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

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

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

$url = html_entity_decode($string,ENT_COMPAT,"UTF-8");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM