加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php源码 fsockopen获取网页内容实例详解

发布时间:2020-12-12 21:44:05 所属栏目:PHP教程 来源:网络整理
导读:PHP fsockopen函数说明: Open Internet or Unix domain socket connection(打开套接字链接) Initiates a socket connection to the resource specified by target . fsockopen() returns a file pointer which may be used together with the other file

PHP fsockopen函数说明:

Open Internet or Unix domain socket connection(打开套接字链接)

Initiates a socket connection to the resource specified by target .

fsockopen() returns a file pointer which may be used together with the other file functions (such as fgets(),fgetss(),fwrite(),fclose(),and feof() ).就是返回一个文件句柄

开启PHP fsockopen这个函数

PHP fsockopen需要 PHP.ini 中 allow_url_fopen 选项开启。

使用fsockopen获取网页内容

具体源代码如下:

$request = "GET $page HTTP/1.0rn";
$request .= "Host: $hostrn";
$request .= "Referer: http://www.manongjc.com/page.htmlrn";
$request .= "User-Agent: PHP test clientrnrn";

$page = array();
fputs ( $fp,$request );
while ( ! feof( $fp ) ) {
$page[] = fgets( $fp,1024 );
}
fclose( $fp );
print "the server returned ".(count($page))." lines!";
?>

以上就是php源码 fsockopen获取网页内容实例详解的知识,有需要的小伙伴可以参考下,谢谢大家对本站的支持!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读