我想從我的網站內的頁面獲取標題標記的內容。但是,file_get_contents被禁用,所以看起來像cURL是我唯一的選擇。這就是我想:
$domain="http://example.com";
ob_start();
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $domain. '/blog/index.php?page=4');
$getit = curl_exec($curl_handle);
curl_close($curl_handle);
ob_end_clean();
preg_match("/<title>(.*)<\/title>/i", $getit, $matches);
$title= $matches[1];
我不得不使用ob_start和清潔,因爲否則稱爲頁面嵌入到我最後的HMTL代碼,我不需要。我只需要獲取標籤值並讓$ title顯示它,但它什麼都不顯示。這裏有什麼問題?
謝謝。
做嘗試打印$ GETIT?或$匹配?並看看結果是什麼 –
是的,getit的結果是「1」,但$匹配只能打印「數組」。 –
完整的HTML你能看到