我想將網頁內容保存到來自多個網址的文件。來自多個網址的file_get_contents
對於開始我從陣列
$site = array(
'url' => 'http://onesite.com/index.php?c='.$row['code0'].'&o='.$row['code1'].'&y='.$row['code2'].'&a='.$row['cod3'].'&sid=', 'selector' => 'table.tabel tr'
);
網站的URL saveving文件,我有嘗試:
foreach($site as $n) {
$referer = 'reffername';
$header[] = "Accept: text/xml,application/xml,application/json,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$opts = array('http'=>array('method'=>"GET",
'header'=>implode('\r\n',$header)."\r\n".
"Referer: $referer\r\n",
'user_agent'=> "Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/2008092313 Ubuntu/9.25 (jaunty) Firefox/3.8"));
$context = stream_context_create($opts);
$data = file_get_contents($site["url"], false, $context);
$file = md5('$id');
file_put_contents($file, $data);
$content = unserialize(file_get_contents($file));
}
這是更好,如果你使用curl_multi函數同時下載多個文件 – gskema
@GytisŠk好吧,但我怎麼能從一個數組中做到這一點,並保存它? –