将变量传递给curl_setopt

时间:2011-05-13 20:10:29

标签: php curl

我希望能够做到以下几点:

 $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);
    }

但是当我转储$ obj时,我得到一个NULL对象,即使$ term打印正常。

1 个答案:

答案 0 :(得分:4)

您应该使用.而不是+

连接您的网址
$url ='http://search.twitter.com/search.json?q=' . $term . '&rpp=100';