PHP Curl Curlopt_returntransfer parameter action Use instance _php skill

Source: Internet
Author: User
Tags curl

Get page content, not output directly to page, curlopt_returntransfer parameter settings

Using PHP curl to get page content or submit data, sometimes you want the returned content to be stored as a variable rather than as a direct output. This time it is necessary to set the Curl Curlopt_returntransfer option to 1 or true.

1, Curl get the page content, direct output Example:

Copy Code code as follows:

<?php
$url = ' http://www.jb51.net ';

$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 get the page content, not directly output examples:

Copy Code code as follows:

<?php
$url = ' http://www.jb51.net ';

$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 fetched and has not been printed on the page.
Curl_close ($ch);
Echo $response;
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.