《PHP應(yīng)用:php源碼 fsockopen獲取網(wǎng)頁內(nèi)容實(shí)例詳解》要點(diǎn):
本文介紹了PHP應(yīng)用:php源碼 fsockopen獲取網(wǎng)頁內(nèi)容實(shí)例詳解,希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
PHP fsockopen函數(shù)說明:PHP實(shí)例
Open Internet or Unix domain socket connection(打開套接字鏈接)PHP實(shí)例
Initiates a socket connection to the resource specified by target .PHP實(shí)例
fsockopen() returns a file pointer which may be used together with the other file functions (such as fgets() , fgetss() , fwrite() , fclose() , and feof() ).就是返回一個(gè)文件句柄PHP實(shí)例
開啟PHP fsockopen這個(gè)函數(shù)PHP實(shí)例
PHP fsockopen需要 PHP.ini 中 allow_url_fopen 選項(xiàng)開啟.PHP實(shí)例
使用fsockopen獲取網(wǎng)頁內(nèi)容PHP實(shí)例
具體源代碼如下:PHP實(shí)例
<?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)容實(shí)例詳解的知識(shí),有需要的小伙伴可以參考下,謝謝大家對(duì)本站的支持!PHP實(shí)例
轉(zhuǎn)載請(qǐng)注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/3223.html