zoukankan      html  css  js  c++  java
  • PHP CURL获取页面内容输出例子

    使用PHP curl获取页面内容或提交数据,有时候希望返回的内容作为变量储存,而不是直接输出。这个时候就必需设置curl的CURLOPT_RETURNTRANSFER选项为1或true。

    1、curl获取页面内容, 直接输出例子:

     

    <?php
    $url = 'https://www.cnblogs.com/xwyphp/';
     
    $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获取页面内容, 不直接输出例子:

    <?php
    $url = 'https://www.cnblogs.com/xwyphp/';
     
    $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); // 已经获取到内容,没有输出到页面上。
    curl_close($ch);
    echo $response;
    ?>
    

     

  • 相关阅读:
    无缝滚动轮播图
    angular 1.6指令与服务
    angular 1.6路由
    javascript 对象
    JavaScript的运算符
    初识JavaScript!
    git常用命令(二)文字版
    CSS水平垂直居中
    收藏的一些牛逼博客
    html5 学习汇总
  • 原文地址:https://www.cnblogs.com/xwyphp/p/9808931.html
Copyright © 2011-2022 走看看