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

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获取网页内容

具体源代码如下:

rush:PHP;"> $request = "GET $page HTTP/1.0\r\n";
$request .= "Host: $host\r\n";
$request .= "Referer: http://www.manongjc.com/page.html\r\n";
$request .= "User-Agent: PHP test client\r\n\r\n";

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

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

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...