2011-05-13 11 views
1

다음 코드는 모든 결과 페이지를 반복하고 각 단계에서 추가 된 각 페이지의 결과가 포함 된 하나의 큰 배열을 반환하는 것으로 가정합니다.CURL을 통해 쿼리 링크를 반복하고 PHP에서 결과 배열 병합

foreach($search_terms as $term){ 
    //populate the obj array by going through all pages 

    //set up connection 
    $ch = curl_init(); 

    // go through all pages and save in an object array 
    for($j=1; $j<16;$j++){ 
     $url ='http://search.twitter.com/search.json?q=' . $term .'&rpp=100&page='.$j.''; 
     curl_setopt($ch, CURLOPT_URL,$url); 
     curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
     $var[$j] = curl_exec($ch); 
     curl_close($ch); 
     $obj = array_merge((array)$obj,(array)json_decode($var[$j], true)); 
    } 
} 

그래도 잘 작동을하지 않는 이러한 오류를 얻고있다 : 당신은 각 반복의 끝에서 그것을습니다

curl_setopt(): 3 is not a valid cURL handle resource 
curl_exec(): 3 is not a valid cURL handle resource 
curl_close(): 3 is not a valid cURL handle resource 
...... and this is repeated all the way from 3-> 7... 
curl_setopt(): 7 is not a valid cURL handle resource 
curl_exec(): 7 is not a valid cURL handle resource 
curl_close(): 7 is not a valid cURL handle resource 

답변

2
//set up connection 
$ch = curl_init(); 
// go through all pages and save in an object array 

for($j=1; $j<16;$j++){ 

당신은 당신의 루프 내부 curl_init()에 대한 호출이 필요합니다.

관련 문제