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

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

WBOY
Release: 2016-06-13 11:30:44
Original
1449 people have browsed it

<?<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>
Copy after login

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template