有人看下面的腳本,爲什麼不列出好奇的內容(< div> </div>),即使地址是正確的。捲曲 - 沒有列出我想知道的內容
<?php
function get_content($url)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();
ob_end_clean();
$divs = '/<div>(.+)<\/div>/U';
preg_match($divs, $string, $matches);
$vysledek = $matches[1];
var_dump($vysledek);
var_dump($url);
}
echo get_content ("http://www.azlyrics.com/lyrics/garthbrooks/midnightsun.html");
?>
的var_dump我寫道: NULL 字符串(59) 「http://www.azlyrics.com/lyrics/garthbrooks/midnightsun.html」
早些時候,我用:
function ziskatlyrics($url)
{
$content = file_get_contents($url);
$first_step = explode('<div>' , $content);
$second_step = explode("</div>" , $first_step[1]);
$obsah = strip_tags($second_step[0]);
return $obsah;
}
echo ziskatlyrics("http://www.azlyrics.com/lyrics/garthbrooks/midnightsun.html");
但它拋出我這個錯誤: 警告:的file_get_contents( http://www.azlyrics.com/...ightsun.html ):無法打開流:HTTP請求失敗!在
我可以做一些事情,使其功能再次? 謝謝你的回答。