php解析url的三个示例_PHP教程

WBOY
Release: 2016-07-13 10:40:23
Original
996 people have browsed it

方法一:

复制代码代码如下:

$url="http://www.baidu.com";
file_get_contents($url);


方法二:
复制代码代码如下:

// CURL 方法
$url="http://www.baidu.com";
$ch = curl_init( );
curl_setopt( $ch,CURLOPT_URL,$url );
curl_setopt( $ch,CURLOPT_HEADER,0 );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER,1 );
$ret= curl_exec( $ch );
curl_close( $ch );
echo $ret;

方法三:

复制代码代码如下:

$url="http://www.baidu.com";
$fp=fopen($url,"r");
$response = '';
while($row = fgets($fp)) {
$response.= trim($row)."\n";
}


注意:如果ping的通但是无法调用远程url,试试wget
复制代码代码如下:

Resolving www.xxx.com... 114.xxx.xxx.xxx
Connecting to www.xxx.com|114.xxx.xxx.xxx|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
10:58:22 ERROR 403: Forbidden.


这样就不可以!

www.bkjia.com true http://www.bkjia.com/PHPjc/718622.html TechArticle 方法一: 复制代码 代码如下: $url="http://www.baidu.com"; file_get_contents($url); 方法二: 复制代码 代码如下: // CURL 方法 $url="http://www.baidu.com"; $c...
Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!