首頁 >後端開發 >php教程 >PHP 使用 stream_get_meta_date ,stream_get_contents 获取网页内容

PHP 使用 stream_get_meta_date ,stream_get_contents 获取网页内容

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-06-23 13:45:011156瀏覽

PHP 使用 获取网页内容:


if (! preg_match('@^https?://@', $url)) {    die('HTTP(s) only.');}$httpOpts = array(    'max_redirects' => 0    ,'timeout' => 3);if ($ua !== '') {    $httpOpts['user_agent'] = $ua;}if ($cook !== '') {    $httpOpts['header'] = "Cookie: {$cook}\r\n";}$ctx = stream_context_create(array(    'http' => $httpOpts));// fetchif (! ($fp = @fopen($url, 'r', false, $ctx))) {    die('Couldn\'t open URL.');}$meta = stream_get_meta_data($fp);$content = stream_get_contents($fp);fclose($fp);

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn