欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php源碼 fsockopen獲取網(wǎng)頁(yè)內(nèi)容實(shí)例詳解

 更新時(shí)間:2016年09月24日 08:26:55   投稿:lqh  
這篇文章主要介紹了php源碼 fsockopen獲取網(wǎng)頁(yè)內(nèi)容實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下

PHP fsockopen函數(shù)說(shuō)明:

Open Internet or Unix domain socket connection(打開(kāi)套接字鏈接)

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() ).就是返回一個(gè)文件句柄

開(kāi)啟PHP fsockopen這個(gè)函數(shù)

PHP fsockopen需要 PHP.ini 中 allow_url_fopen 選項(xiàng)開(kāi)啟。

使用fsockopen獲取網(wǎng)頁(yè)內(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)頁(yè)內(nèi)容實(shí)例詳解的知識(shí),有需要的小伙伴可以參考下,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論