$url = $_POST[‘url‘]; $ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $content = curl_exec($ch); curl_close($ch); //处理内容 $str = $content; $start = ‘<div class="buyer_count">‘; $end = ‘</div>‘; $rowtmp = get_sub_content($str, $start, $end); $row = strip_tags(substr(trim($rowtmp),0,-9)); sleep(2);//休息2秒看效果 ob_flush(); flush();
get_sub_content($str, $start, $end){ if ( $start == ‘‘ || $end == ‘‘ ){ return; } $str = explode($start, $str); $str = explode($end, $str[1]); return $str[0]; }
原文地址:http://my.oschina.net/xinson/blog/322840