PHPcurl instance, phpcurl instance _ PHP Tutorial

Source: Internet
Author: User
PHPcurl uses the instance and phpcurl instance. PHPcurl uses instances. phpcurl provides an overview of the previous two articles in this blog: Introduction to curl and libcurl and introduction to using curl in PHP to briefly introduce the use of curl in PHP, however, in PHP, curl enables PHP curl to use instances and phpcurl instances.

Overview

The previous two articles in this blog: Introduction to curl and libcurl and the use of curl in PHP briefly introduced the use of curl in PHP, but the use of curl in PHP is not simple, in particular, curl configuration items. This article will explain several PHP instances so that you can better understand curl.

Instance: capture page

Using curl to capture a page is relatively simple, but here you need to note that curl will directly output the captured page to the browser by default. However, we often encounter the problem of obtaining captured content and processing the content before performing operations. Therefore, two different situations are written here.

Output directly to the browser

The code is as follows:
<? Php
$ Url = "www.baidu.com ";
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_exec ($ ch );
Curl_close ($ ch );
?>

Run the above code and we will see the Baidu homepage directly.

Not directly output to the browser

If we do not want the content captured by curl to be directly output to the browser, we need to set "CURLOPT_RETURNTRANSFER" of curl to true, so that the content captured by curl will appear as the return value of the curl_exec () function.
The code is as follows:
<? Php
$ Url = "www.baidu.com ";
$ Content = '';
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, TRUE );
/*
* According to the manual, it seems that PHP5.1.3 and earlier versions must be used together with CURLOPT_BINARYTRANSFER,
* In versions later than 5.1.3, this configuration item has been deprecated.
*/
// Curl_setopt ($ ch, CURLOPT_BINARYTRANSFER, TRUE );
$ Content = curl_exec ($ ch );
Var_dump ($ content );
Curl_close ($ ch );
?>

Run the code. we can see that the source code of the obtained webpage is output on the page.

Http://www.bkjia.com/PHPjc/1026059.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1026059.htmlTechArticlePHP curl use instance, phpcurl instance Overview this blog's first two articles: curl and libcurl introduction and PHP use curl to PHP curl use a simple introduction, however, in PHP, curl causes...

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.