这是我的代码:
function get_data($url)
{
$ch = curl_init();
$timeout = 15;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_USERAGENT, random_user_agent());
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
//Grab HTML
$urllist = fopen("links.txt", "r+");
for ($j = 0; $j <= 50; $j++)
{
$post = rtrim(fgets($urllist));
echo $post;
$html = get_data($post);
echo $html;
问题:当我使用时,我get_data("http://url.com")
在 html 中获得了正确的数据。但是当我使用变量传递 url 时,$html
什么也不返回。
$post 在我检查时拥有正确的网址。这不是正确的使用方法吗get_data($post);
卷曲信息给出:
我明白了:
array(20) {
["url"]=> string(68) "http://secret-url.com"
["content_type"]=> string(9) "text/html"
["http_code"]=> int(301)
["header_size"]=> int(255)
["request_size"]=> int(340)
["filetime"]=> int(-1)
["ssl_verify_result"]=> int(0)
["redirect_count"]=> int(0)
["total_time"]=> float(0.095589)
["namelookup_time"]=> float(0.012224)
["connect_time"]=> float(0.049399)
["pretransfer_time"]=> float(6.5E-5)
["size_upload"]=> float(0)
["size_download"]=> float(0)
["speed_download"]=> float(0)
["speed_upload"]=> float(0)
["download_content_length"]=> float(0)
["upload_content_length"]=> float(0)
["starttransfer_time"]=> float(0.095534)
["redirect_time"]=> float(0)
}