php获取远程页面 de ion keywords信息

我们可以直接使用php get_ _tags函数获取远程页面 de ion keywords信息,具体实现代码如下:

<?php
$tags = get_ _tags(\'http://www.manongjc.com/\');
$keywords = $tags[\'keywords\'];
$de ion = $tags[\'de ion\'];
$author = $tags[\'author\'];

echo \"<b>De ion:</b> $de ion<br>\";
echo \"<b>Keywords:</b> $keywords<br>\";
echo \"<b>Author:</b> $author<br>\";
?>

 

php获取远程页面 标题信息

首先,打开/读取远程页面。打开读取远程页面可以使用fopen()函数,也可以使用file_get_contents()函数,这里我们使用fopen()函数,代码如下:

<?php
$url = \"http://www.manongjc.com\";
$page = fopen($url, \'r\');
$content = \"\";
while( !feof( $page ) ) {
$buffer = trim( fgets( $page, 4096 ) );
$content .= $buffer;
}
?>

接着,我们提取 标签之间的文本:

<?php
eregi(\'\',$content,$tmp);
$result = ereg_replace(\'[[:blank:]]\',\' \',$tmp[1]);
echo \"$result\";
?>

 

php获取远程页面的头信息

php开发人员可以用下面的代码提取来自远程页面的 信息:

<?php
$fp = fopen(\'http://www.baidu.com\', \'r\');
// Creates variable $http_response_header
/*  http://www.manongjc.com/article/1424.html */
print_r($http_response_header);
// or
$ _data = stream_get_ _data($fp);
print_r($ _data);
?>

运行结果:

Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Date: Wed, 31 Aug 2016 05:03:49 GMT
    [2] => Content-Type: text/html
    [3] => Content-Length: 14613
    [4] => Last-Modified: Tue, 23 Aug 2016 03:40:28 GMT
    [5] => Connection: Close
    [6] => Vary: Accept-Encoding
    [7] => Set-Cookie: BAIDUID=C75A224EC0342039FBDAF3CC9B0E6F8E:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
    [8] => Set-Cookie: BIDUPSID=C75A224EC0342039FBDAF3CC9B0E6F8E; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
    [9] => Set-Cookie: PSTM=1472619829; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
    [10] => P3P: CP=\" OTI DSP COR IVA OUR IND COM \"
    [11] => Server: BWS/1.1
    [12] => X-UA-Compatible: IE=Edge,chrome=1
    [13] => Pragma: no-cache
    [14] => Cache-control: no-cache
    [15] => Accept-Ranges: bytes
)
Array
(
    [wrapper_data] => Array
        (
            [0] => HTTP/1.1 200 OK
            [1] => Date: Wed, 31 Aug 2016 05:03:49 GMT
            [2] => Content-Type: text/html
            [3] => Content-Length: 14613
            [4] => Last-Modified: Tue, 23 Aug 2016 03:40:28 GMT
            [5] => Connection: Close
            [6] => Vary: Accept-Encoding
            [7] => Set-Cookie: BAIDUID=C75A224EC0342039FBDAF3CC9B0E6F8E:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
            [8] => Set-Cookie: BIDUPSID=C75A224EC0342039FBDAF3CC9B0E6F8E; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
            [9] => Set-Cookie: PSTM=1472619829; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
            [10] => P3P: CP=\" OTI DSP COR IVA OUR IND COM \"
            [11] => Server: BWS/1.1
            [12] => X-UA-Compatible: IE=Edge,chrome=1
            [13] => Pragma: no-cache
            [14] => Cache-control: no-cache
            [15] => Accept-Ranges: bytes
        )

    [wrapper_type] => http
    [stream_type] => tcp_socket/ssl
    [mode] => r
    [unread_bytes] => 0
    [seekable] => 
    [uri] => http://www.baidu.com
    [timed_out] => 
    [blocked] => 1
    [eof] => 
)
收藏 打印