Home >Backend Development >PHP Tutorial >php通过socket获取网页内容的简单示例

php通过socket获取网页内容的简单示例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-20 13:03:51914browse

php通过socket获取网页内容的简单示例,请看下面代码:

<p>$url='www.scutephp.com';</p>$fp=fsockopen($url,80,&$errno,&$errstr,10);<br />if(!$fp){<br />	echo "$errstr ($errno)<br>\n";<br />}else{<br />	fputs($fp,"GET / HTTP/1.0\nHost: ".$url."\n\n");<br />	while(!feof($fp)){<br />		echo fgets($fp,128);<br />	}<br />	fclose($fp);<br />}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn