Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use curl_exec function in php

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to use the curl_exec function in php, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

There is a parameter CURLOPT_RETURNTRANSFER in CURL: this parameter returns the information obtained by curl_exec () as a file stream rather than directly outputting it. For example, the function of the CURLOPT_RETURNTRANSFER parameter is to assign the content obtained by CRUL to the variable. It defaults to 0, which directly returns the text stream of the obtained output, and sometimes it is not good for us to use the return value for judgment or other purposes. So, sometimes we want the returned content to be stored as a variable rather than output directly, so what should we do?

The method of getting the return value of phpcurl_exec () function CURL

In fact, CURLOPT_RETURNTRANSFER can be set, if set to CURLOPT_RETURNTRANSFER1, it will use PHPcurl to get the page content or submit data, stored as a variable, rather than direct output.

Curl_setopt ($ch,CURLOPT_RETURNTRANSFER,1)

Example of the phpcurl_exec () function

1. Curl acquires the content of the page and outputs examples directly:

$url=' http://www.php.cn';

$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)

? >

Run the code and you will find that the acquired cul content will be output directly.

2. Curl acquires the content of the page without directly outputting examples:

$url=' http://www.php.cn';

$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 and not output to the page.

Curl_close ($ch)

Echo$response

? >

When we set CURLOPT_RETURNTRANSFER to 1, the page has no output, and we assign the acquired content to a variable $response, the variable $response output with echo.

The above is all the contents of the article "how to use the curl_exec function in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report