drjk87189
2011-05-13 20:10
浏览 48
已采纳

将变量传递给curl_setopt

I want to be able to do the following:

 $search_terms[0]='frank';
    $search_terms[1]='sinatra';
    $search_terms[2]='beyonce';

    foreach($search_terms as $term){
    $ch = curl_init();
    $url ='http://search.twitter.com/search.json?q=' + $term +'&rpp=100';
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);

    $var = curl_exec($ch);


    curl_close($ch);

    $obj = json_decode($var, true);

echo $term;
    var_dump($obj);
    }

But I get a NULL object when i dump $obj, even though $term prints ok.

图片转代码服务由CSDN问答提供 功能建议

我希望能够执行以下操作:</ p>

   $ search_terms [0] ='frank'; 
 $ search_terms [1] ='sinatra'; 
 $ search_terms [2] ='beyonce'; 
 
 foreach($ search_terms as $ term){
 $  ch = curl_init(); 
 $ url ='http://search.twitter.com/search.json?q ='+ $ term +'&amp; rpp = 100'; 
 curl_setopt($ ch,CURLOPT_URL,  $ url); 
 curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1); 
 
 $ var = curl_exec($ ch); 
 
 
 curl_close($ ch); 
 
 $ obj = json_decode(  $ var,true); 
 
echo $ term; 
 var_dump($ obj); 
} 
 </ code> </ pre> 
 
 

但是当我转储时我得到一个NULL对象 $ obj,即使$ term打印好。</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题