PHP菜鸟博客_共同学习分享PHP技术心得【PHP爱好者】
PHP curl 得到返回值且不显示在页面上
2015-10-26 菜鸟站长


<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://www.wlphp.com/");

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);

curl_close($ch);

?>



当执行curl_exec($ch);后会即刻输出返回内容。



救不让它输出而得到它返回的内容的方法。




  1. $c = curl_init();  


  2. curl_setopt($c, CURLOPT_URL, $url);  


  3. //Tell curl to write the response to a variable  


  4. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);      得到返回值且不显示在页面上




  5. // The maximum number of seconds to allow cURL functions to execute.  


  6. curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 60);    




  7. $buf = curl_exec($c);  



 将内容赋值给变量

发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容