欢迎来到PHP菜鸟博客    登录
我的订单    |  会员中心  
     
就算这个世道烂成一堆粪坑,那也不是你吃屎的理由!!
购物车

首页 > php > 产品详情

PHP curl 得到返回值且不显示在页面上

 

9999.00    (库存:有货)

已超出库存数量!

  • 详情

<?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);  

 将内容赋值给变量