php源碼 fsockopen獲取網(wǎng)頁內(nèi)容實例詳解
PHP fsockopen函數(shù)說明:
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這個函數(shù)
PHP fsockopen需要 PHP.ini 中 allow_url_fopen 選項開啟。
使用fsockopen獲取網(wǎng)頁內(nèi)容
具體源代碼如下:
<?php $host = "www.manongjc.com"; $page = "/index.htm"; $fp = fsockopen( "$host", 80, $errno, $errdesc ); if ( ! $fp ) { die ( "Couldn't connect to $host:\nError: $errno\nDesc: $errdesc\n" ); } $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獲取網(wǎng)頁內(nèi)容實例詳解的知識,有需要的小伙伴可以參考下,謝謝大家對本站的支持!
相關(guān)文章
PHP將英文數(shù)字轉(zhuǎn)換為阿拉伯數(shù)字實例講解
在本篇文章里小編給大家分享了關(guān)于PHP將英文數(shù)字轉(zhuǎn)換為阿拉伯數(shù)字實例內(nèi)容,有興趣的朋友們可以參考學(xué)習(xí)下。2019-01-01thinkPHP簡單導(dǎo)入和使用阿里云OSSsdk的方法
這篇文章主要介紹了thinkPHP簡單導(dǎo)入和使用阿里云OSSsdk的方法,簡單說明了阿里云OSS的php sdk下載地址及thinkPHP導(dǎo)入與使用OSSsdk的方法,需要的朋友可以參考下2017-03-03