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

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

WBOY
WBOY원래의
2016-06-13 11:30:441457검색

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

 

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.