Home > php教程 > php手册 > PHP curl CURLOPT_RETURNTRANSFER参数的作用使用实例,curl实例

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

WBOY
Release: 2016-06-13 09:15:24
Original
1107 people have browsed it

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

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

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

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

复制代码 代码如下:


$url = 'http://www.bkjia.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.bkjia.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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template