function curl_get($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$data = curl_exec($ch);
print_r(curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD));
curl_close($ch);
return $data;
}
このページ「wikipedia.sfstate.us/Scarves」に対して文字列を一致させようとしていました。関数を使用してコンテンツを取得します。
$url = "http://wikipedia.sfstate.us/Scarves";
$html = curl_get($url);
var_dump($html);
結果は次のようになります。
812 //CURLINFO_SIZE_DOWNLOAD
string(812) "..." //$html string where the content is stored
ただし、ファイル全体では 64612 バイトです (web-sniffer.net による結果)。64612 = 1024 * 63 + 812 です。つまり、ファイルの最後の 812 バイトしか取得していません。
なぜこれが起こるのでしょうか?コンテンツ全体を取得する方法についてのアイデアはありますか? ありがとう。
PS: sth も試しました。以下のようですが、役に立ちません
if(strlen($html) < 1024){
$html = '';
$i = 0;
while($content = file_get_contents($url, FILE_TEXT, NULL, $i, $i + 1023)){
$html .= $content;
$i += 1023;
}
}