开发者

passing a variable into curl_setopt

开发者 https://www.devze.com 2023-03-05 14:25 出处:网络
I want to be able to do the following: $search_terms[0]=\'frank\'; $search_terms[1]=\'sinatra\'; $search_terms[2]=\'beyonce\';

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开发者_StackOverflow中文版, true);

echo $term;
    var_dump($obj);
    }

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


You should concat your url with . instead of +:

$url ='http://search.twitter.com/search.json?q=' . $term . '&rpp=100';
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号