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

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

WBOY
Lepaskan: 2016-06-13 11:30:44
asal
1452 orang telah melayarinya

<?<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>
Salin selepas log masuk

 

sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan