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擷取網頁內容
具體原始碼如下:
<?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擷取網頁內容執行個體詳解的知識,有需要的小夥伴可以參考下,謝謝大家對本站的支援!