首页 > php教程 > php手册 > while循环中不支持循环使用curl

while循环中不支持循环使用curl

WBOY
发布: 2016-06-13 11:30:44
原创
1444 人浏览过

<?<span php 
</span><span $link</span> = <span mysql_connect</span>('localhost', 'sms', 'sms'<span );
</span><span mysql_select_db</span>('sms', <span $link</span><span );
</span><span mysql_query</span>("set names utf8"<span );
</span><span $sql</span> = "<span 
SELECT phone,chang, msg, linkid, mo_time FROM tables '</span>"<span ;

</span><span $result</span> = <span mysql_query</span>(<span $sql</span>,<span $link</span><span );
</span><span $array</span> = <span array</span><span ();
</span><span while</span>(<span $row</span> = <span mysql_fetch_array</span>(<span $result</span><span )){


    </span><span $linkid</span> = <span $row</span>['phone'].<span date</span>("YmdHis", <span strtotime</span>(<span $row</span>['mo_time'<span ]));
    </span><span $str</span> = "SPNUM=".<span $row</span>['chang']."&MOBILE=".<span $row</span>['phone']."&CONTENT=".<span urlencode</span>(<span $row</span>['msg'])."&MOTIME=".<span urlencode</span>(<span $row</span>['mo_time'])."&LINKID=".<span $linkid</span><span ;

    </span><span $url</span> = "www.baidu.com?".<span $str</span><span ; 
    </span><span $array</span>[] = <span $url</span><span ;
    </span><span //</span><span var_dump($url); 这里使用curl访问,只能访问一条随后就中断了,只能在上面存放到数组中</span>
    <span /*</span><span $result = file_get_contents($url);
    var_dump($result);</span><span */</span>
    <span /*</span><span $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_TIMEOUT, 40);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
     // 4. 释放curl句柄
      curl_close($ch);</span><span */</span><span 
}
</span><span //</span><span var_dump($array); 
//这里使用foreach循环执行curl命令</span>
<span foreach</span> (<span $array</span> <span as</span> <span $url</span><span ) {
    </span><span var_dump</span>(<span $url</span><span );
    </span><span $ch</span> = curl_init(<span $url</span><span );
    curl_setopt(</span><span $ch</span>, CURLOPT_TIMEOUT, 40<span );
    curl_setopt(</span><span $ch</span>, CURLOPT_RETURNTRANSFER, <span true</span><span );
    </span><span $result</span> = curl_exec(<span $ch</span><span );
     </span><span //</span><span  4. 释放curl句柄</span>
      curl_close(<span $ch</span><span );
      </span><span var_dump</span>(<span $result</span><span );
}</span>
登录后复制

 

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板