Home > Backend Development > PHP Tutorial > PHP curl CURLOPT_RETURNTRANSFER参数的作用使用实例_PHP

PHP curl CURLOPT_RETURNTRANSFER参数的作用使用实例_PHP

WBOY
Release: 2016-05-31 13:17:28
Original
870 people have browsed it

获取页面内容,不直接输出到页面,CURLOPT_RETURNTRANSFER参数设置   

使用PHP curl获取页面内容或提交数据,有时候希望返回的内容作为变量储存,而不是直接输出。这个时候就必需设置curl的CURLOPT_RETURNTRANSFER选项为1或true。

1、curl获取页面内容, 直接输出例子:

代码如下:


$url = 'http://www.bitsCN.com';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_exec($ch);
curl_close($ch);
?>

2、curl获取页面内容, 不直接输出例子:

代码如下:


$url = 'http://www.bitsCN.com';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch); // 已经获取到内容,没有输出到页面上。
curl_close($ch);
echo $response;
?>

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template