脚本宝典收集整理的这篇文章主要介绍了php:file_get_contents编码问题,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
header('Content-tyPE: text/plain; charset=utf-8'); // optional error_reporting(E_ALL | E_STRICT); $context = stream_context_create(array( 'http' => array( 'method' => 'POST','header' => implode("\r\n",array( 'Content-type: application/x-www-form-urlencoded','Accept-Language: en-us,en;q=0.5',// optional 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7' // optional )),'content' => http_build_query(array( 'prev' => '_t','hl' => 'en','ie' => 'UTF-8','text' => 'hello','sl' => 'en','tl' => 'ru' )) ) )); $page = file_get_contents('http://translate.google.com/translate_t',false,$context); require '../simplehtMLdom/simple_html_dom.PHP'; $dom = str_get_html($page); $translation = $dom->find('#result_Box',0)->plaintext; echo $translation;
标记为可选的行是没有它们的输出相同的行.但我得到了奇怪的人物……
������
我试过了
echo mb_convert_encoding($translation,'UTF-8');
但我明白了
ÐÒÉ×ÅÔ
更新:
>忘了提到我所有的PHP
文件以UTF-8编码而没有
BOM
>当我改变“to”语言
到“en”,即从中翻译
英语到英语,它运作正常.
>我不认为我正在使用的库正在弄乱它,因为我试图输出整个$@L_777_9@而不将其传递给库函数.
>我使用的是PHP 5
其次,您可以尝试传递FILE_TEXT标志,如下所示:
$page = file_get_contents('http://translate.google.com/translate_t',FILE_TEXT,$context);
以上是脚本宝典为你收集整理的php:file_get_contents编码问题全部内容,希望文章能够帮你解决php:file_get_contents编码问题所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。