Home > Backend Development > PHP Tutorial > PHP curl CURLOPT_RETURNTRANSFER parameter usage examples, curl examples_PHP tutorial

PHP curl CURLOPT_RETURNTRANSFER parameter usage examples, curl examples_PHP tutorial

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

PHP curl CURLOPT_RETURNTRANSFER parameter usage example, curl example

Get the page content, do not output it directly to the page, CURLOPT_RETURNTRANSFER parameter setting

Use PHP curl to obtain page content or submit data. Sometimes you want the returned content to be stored as a variable instead of output directly. At this time, you must set curl's CURLOPT_RETURNTRANSFER option to 1 or true.

1. Curl gets the page content and outputs it directly. Example:

Copy code The code is as follows:

$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 gets the page content without outputting it directly. Example:

Copy code The code is as follows:

$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); //The content has been obtained but has not been output to the page.
curl_close($ch);
echo $response;
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/954661.htmlTechArticlePHP curl CURLOPT_RETURNTRANSFER parameter usage example, curl instance obtains page content, does not directly output to the page, CURLOPT_RETURNTRANSFER parameter setting Use PHP curl to get the content of the page...
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