Home > Backend Development > PHP Tutorial > PHP 使用 stream_get_meta_date ,stream_get_contents 获取网页内容

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:45:01
Original
1167 people have browsed it

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);
Copy after login

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template