1

我想从 google 下载这个链接,它是 php 的 mage txt 文件。

当我通过浏览器执行此操作时,unicode 是正确的并且一切都正确,但是当我执行此操作时,curlfile_get_content包含错误的字母。有什么区别,我应该如何解决?

由浏览器下载

[[["سلام","你好","",""]],[["感叹词",["سلام","هالو","الو"],[["سلام",["你好", "嗨","阿罗哈","万岁"]],["هالو",["你好","你好","你好"]],["الو",["你好"]]]]], "en",,[["سلام",[5],0,0,1000,0,1,0]],[["hello",4,,,""],["hello",5, [["سلام",1000,0,0],["خوش",0,0,0],["میهمان گرامی",0,0,0],["خوش آمدید",0,0,0] ,["درود کاربر",0,0,0]],[[0,5]],"你好"]],,,[["en"]],65]

通过以下php脚本下载:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
$t = file_get_contents("http://translate.google.com/translate_a/t?client=t&hl=en&sl=auto&tl=fa&multires=1&prev=btn&ssel=0&tsel=3&uptl=fa&alttl=en&sc=1&text=hello");
$f = fopen("t.txt", "w+");
fwrite($f, $t);
fclose($f);
?>
</body></html>
[[["ÓáÇã","你好","",""]],[["感叹词",["ÓáÇã","åÇáæ","Çáæ"],[["ÓáÇã",["你好", "hi","aloha","all hail"]],["åÇáæ",["hallo","hello","halloo"]],["Çáæ",["hello"]]]]], "en",,[["ÓáÇã",[5],0,0,1000,0,1,0]],[["你好",4,,,""],["你好",5, [["ÓáÇã",1000,0,0],["ÎæÔ",0,0,0],["ã\u06CCåãÇä ÑÇã\u06CC",0,0,0],["ÎæÔ ÂãÏ\u06CCÏ", 0,0,0],["ÏÑæÏ ÇÑÈÑ",0,0,0]],[[0,5]],"hello"]],,,[["en"]],4]

标题:

标题是:
HTTP/1.1 200 正常
Pragma:无缓存
日期:格林威治标准时间 2012 年 5 月 25 日星期五 22:29:12
到期:格林威治标准时间 2012 年 5 月 25 日星期五 22:29:12
缓存控制:私有,max-age=600
内容类型:文本/javascript;字符集=UTF-8
内容语言:fa
设置 Cookie:PREF=ID=b6c08a0545f50594:TM=1337984952:LM=1337984952:S=Sf1xcow2qPZrFeu0;expires=星期日,2014 年 5 月 25 日 22:29:12 GMT;路径=/; 域=.google.com
X-Content-Type-Options: nosniff
内容处置:附件
服务器:HTTP 服务器(未知)
X-XSS-防护:1;模式=块
传输编码:分块
4

3 回答 3

1

Add parameters ie=UTF-8 and oe=UTF-8 to query string of the url:

$t = file_get_contents("http://translate.google.com/translate_a/t?ie=UTF-8&oe=UTF-8&client=t&hl=en&sl=auto&tl=fa&multires=1&prev=btn&ssel=0&tsel=3&uptl=fa&alttl=en&sc=1&text=hello");
于 2013-05-02T20:54:26.713 回答
0

这对我有用一次,因为我正要将大量代码扔进垃圾箱!也许它也会帮助你

iconv( 'CP1252', 'UTF-8', $string); 
于 2012-05-25T21:37:35.790 回答
0
于 2012-05-26T07:41:57.493 回答