1

I have made a script that searches for specific twitter tweets. The problem is that it displays the whole array, and I want to display only the username and the tweet.

function searchHashtag($search,$count){
    $consumerKey = "xxx";
    $consumerSecret = "xxx";
    $oauthAccessToken = "xxx";
    $oauthAccessTokenSecret = "xxx";

    $twitter = new TwitterOAuth($consumerKey, $consumerSecret, $oauthAccessToken, $oauthAccessTokenSecret);

    $url = "https://api.twitter.com/1.1/search/tweets.json";
    $tweetArray = array();
    $parameters = array('q' => $search, 'result_type' => 'recent', 'count' => $count);
    $tweets = $twitter->get($url,$parameters);

    foreach($tweets->statuses as $tweet){
        $tweetArray[] = array('text'=>$tweet->text, 'username'=>$tweet->user->name);
    }
    return $tweetArray;
}

$landbouw = searchHashtag($searchlandbouw,$countlandbouw);
var_dump($landbouw);

I know I can use return $tweetArray[1][1]; Then it displays only the username, but it also displays the amount of characters. Is there a easy way to display only the username and tweet, one by one?

4
  • Can I see the array structure? Print echo "<pre>"; print_r($tweetArray); echo "</pre>"; & Paste it on pastebin.com & share the url. Commented Jan 20, 2014 at 15:18
  • pastebin.com/EugQDvE8 this is the url Commented Jan 20, 2014 at 15:23
  • What's the problem? You can loop through array or do you have any issue for looping that array? Commented Jan 20, 2014 at 15:25
  • The problem is that i can't get the data out of that array. When I use the return function, it displays a lot more data then in the url I just send you. It displays if the context is a string or an integer, how many characters there are used etc. I just want to see the username and the tweet, nothing more, nothing less. But I am unable to do that. (I'm new to php, and i'm trying some stuff out) Commented Jan 20, 2014 at 15:29

1 Answer 1

1

If your array structure is exactly like in http://pastebin.com/EugQDvE8. You can apply for loop in $landbouw to get the username and the tweet.

Just try with this.

for($i=0;$i<count($landbouw);$i++)
{
  echo "Tweet : ".$landbouw[$i]['text']."<br/>";
  echo "Username : ".$landbouw[$i]['username']."<br/><br/>";
}  
Sign up to request clarification or add additional context in comments.

8 Comments

It is axactly like that. But it won't work. I get a blank page if I use that code. Can't see other content either.
For getting the response data (array output), Have you assigned the function call searchHashtag(param1,param2) to a variable?
@bbvanee why there is a ` @ the end? Typo?
I'll try it now. Does placement matter?
Still, it doesn't work. I do see my other content. but it displays nothing. And when I comment the return $tweetArray, I get a NULL, maybe that says something?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.