手机
当前位置:查字典教程网 >编程开发 >php教程 >php源码 fsockopen获取网页内容实例详解
php源码 fsockopen获取网页内容实例详解
摘要:PHPfsockopen函数说明:OpenInternetorUnixdomainsocketconnection(打开套接字链接)Init...

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

具体源代码如下:

<"www.manongjc.com"; $page = "/index.htm"; $fp = fsockopen( "$host", 80, $errno, $errdesc ); if ( ! $fp ) { die ( "Couldn't connect to $host:nError: $errnonDesc: $errdescn" ); } $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获取网页内容实例详解的知识,有需要的小伙伴可以参考下,谢谢大家对本站的支持!

【php源码 fsockopen获取网页内容实例详解】相关文章:

PHP的Socket通信之UDP通信实例

PHP中在数据库中保存Checkbox数据(1)

php使用GD实现颜色渐变实例

PHP应用分页显示制作详细讲解

3

PHP生成静态页面详解

phplot生成图片类用法详解

用Socket发送电子邮件

php实现递归抓取网页类实例

phpcms手机内容页面添加上一篇和下一篇

精品推荐
分类导航