Avatar of madstylex
madstylex
 asked on

php script to extract tweets from json data

I have a script in linux mint that fetches twitter statuses using the following input from the command line:

php twitter.php show username number

The script returns the output in JSON format.

How can I add to this script so that it removes the twitter statuses only from the json data and displays  them in a list?

The code is shown below (my developer token data has been removed).

<?php

session_start();
require_once("twitteroauth.php"); //Path to twitteroauth library



$task = $argv[1];
$twitteruser = $argv[2];
$twitterkeyword = $argv[2];
$notweets = $argv[3];
$consumerkey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$consumersecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$accesstoken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$accesstokensecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

if ($task == "show") {
function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
  $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
  return $connection;
}

$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);

//if ($task == "show") {

$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);

echo json_encode($tweets);
//echo $tweets;
}

echo $notweets
?>

Open in new window

PHPScripting LanguagesLinux

Avatar of undefined
Last Comment
madstylex

8/22/2022 - Mon
Ray Paseur

script returns the output in JSON format
Please post the test data (the JSON string) that represents what you're working with.  Please show us what you would want the PHP script to produce after parsing the JSON string.  Armed with that information, we can probably show you a tested and working code sample.
madstylex

ASKER
Hi Ray,

Here is the output from the command:

php gettweets.php show Intel 2

[{"created_at":"Sat May 03 16:15:01 +0000 2014","id":462626389251072000,"id_str":"462626389251072000","text":"Ready for travel season? A variety of apps could make tablets the essential travel companion http:\/\/t.co\/Ha0RzAr8Bn http:\/\/t.co\/Xkwfb2Hh64","source":"<a href=\"http:\/\/www.sprinklr.com\" rel=\"nofollow\">Sprinklr<\/a>","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2803191,"id_str":"2803191","name":"Intel","screen_name":"intel","location":"\u00dcT: 37.575291,-122.341831","description":"Intel news, views & events about global tech innovation.","url":"http:\/\/t.co\/MYZ7uTo0nG","entities":{"url":{"urls":[{"url":"http:\/\/t.co\/MYZ7uTo0nG","expanded_url":"http:\/\/iq.intel.com","display_url":"iq.intel.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":3072725,"friends_count":1202,"listed_count":9083,"created_at":"Thu Mar 29 07:22:48 +0000 2007","favourites_count":472,"utc_offset":-25200,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":true,"statuses_count":4808,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"FFFFFF","profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/433119978913427457\/_mEcPZWl.jpeg","profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/433119978913427457\/_mEcPZWl.jpeg","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/458704019897061377\/GPLhINBv_normal.png","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/458704019897061377\/GPLhINBv_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2803191\/1398790022","profile_link_color":"0070C5","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"86C6E3","profile_text_color":"444444","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":70,"favorite_count":47,"entities":{"hashtags":[],"symbols":[],"urls":[{"url":"http:\/\/t.co\/Ha0RzAr8Bn","expanded_url":"http:\/\/intel.ly\/1kwMf49","display_url":"intel.ly\/1kwMf49","indices":[93,115]}],"user_mentions":[],"media":[{"id":462626389146234881,"id_str":"462626389146234881","indices":[116,138],"media_url":"http:\/\/pbs.twimg.com\/media\/BmuUP_TIcAEjJnR.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/BmuUP_TIcAEjJnR.jpg","url":"http:\/\/t.co\/Xkwfb2Hh64","display_url":"pic.twitter.com\/Xkwfb2Hh64","expanded_url":"http:\/\/twitter.com\/intel\/status\/462626389251072000\/photo\/1","type":"photo","sizes":{"small":{"w":340,"h":227,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"large":{"w":525,"h":350,"resize":"fit"},"medium":{"w":525,"h":350,"resize":"fit"}}}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"created_at":"Fri May 02 23:45:00 +0000 2014","id":462377247161470977,"id_str":"462377247161470977","text":"Wish your smartphone camera helped you take better selifes? Meet the Zenfone by @ASUS - http:\/\/t.co\/Hu4UVRB8LL http:\/\/t.co\/kVH3CsuEHe","source":"<a href=\"http:\/\/www.sprinklr.com\" rel=\"nofollow\">Sprinklr<\/a>","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2803191,"id_str":"2803191","name":"Intel","screen_name":"intel","location":"\u00dcT: 37.575291,-122.341831","description":"Intel news, views & events about global tech innovation.","url":"http:\/\/t.co\/MYZ7uTo0nG","entities":{"url":{"urls":[{"url":"http:\/\/t.co\/MYZ7uTo0nG","expanded_url":"http:\/\/iq.intel.com","display_url":"iq.intel.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":3072725,"friends_count":1202,"listed_count":9083,"created_at":"Thu Mar 29 07:22:48 +0000 2007","favourites_count":472,"utc_offset":-25200,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":true,"statuses_count":4808,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"FFFFFF","profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/433119978913427457\/_mEcPZWl.jpeg","profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/433119978913427457\/_mEcPZWl.jpeg","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/458704019897061377\/GPLhINBv_normal.png","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/458704019897061377\/GPLhINBv_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2803191\/1398790022","profile_link_color":"0070C5","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"86C6E3","profile_text_color":"444444","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":50,"favorite_count":55,"entities":{"hashtags":[],"symbols":[],"urls":[{"url":"http:\/\/t.co\/Hu4UVRB8LL","expanded_url":"http:\/\/intel.ly\/1kxsoSz","display_url":"intel.ly\/1kxsoSz","indices":[88,110]}],"user_mentions":[{"screen_name":"ASUS","name":"ASUS","id":591646425,"id_str":"591646425","indices":[80,85]}],"media":[{"id":462377247010488322,"id_str":"462377247010488322","indices":[111,133],"media_url":"http:\/\/pbs.twimg.com\/media\/BmqxqAhIgAIalgZ.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/BmqxqAhIgAIalgZ.jpg","url":"http:\/\/t.co\/kVH3CsuEHe","display_url":"pic.twitter.com\/kVH3CsuEHe","expanded_url":"http:\/\/twitter.com\/intel\/status\/462377247161470977\/photo\/1","type":"photo","sizes":{"small":{"w":340,"h":222,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"large":{"w":541,"h":353,"resize":"fit"},"medium":{"w":541,"h":353,"resize":"fit"}}}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"}]

Open in new window


I would like it look like:

username

'date and time' 'tweet'
rinfo

$json_data = '[{"created_at":"Sat May 03 16:15:01 +0000 2014","id":462626389251072000,"id_str":"462626389251072000","text":"Ready for travel season? A variety of apps could make tablets the essential travel companion http:\/\/t.co\/Ha0RzAr8Bn http:\/\/t.co\/Xkwfb2Hh64","source":"<a href=\"http:\/\/www.sprinklr.com\" rel=\"nofollow\">Sprinklr<\/a>","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2803191,"id_str":"2803191","name":"Intel","screen_name":"intel","location":"\u00dcT: 37.575291,-122.341831","description":"Intel news, views & events about global tech innovation.","url":"http:\/\/t.co\/MYZ7uTo0nG","entities":{"url":{"urls":[{"url":"http:\/\/t.co\/MYZ7uTo0nG","expanded_url":"http:\/\/iq.intel.com","display_url":"iq.intel.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":3072725,"friends_count":1202,"listed_count":9083,"created_at":"Thu Mar 29 07:22:48 +0000 2007","favourites_count":472,"utc_offset":-25200,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":true,"statuses_count":4808,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"FFFFFF","profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/433119978913427457\/_mEcPZWl.jpeg","profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/433119978913427457\/_mEcPZWl.jpeg","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/458704019897061377\/GPLhINBv_normal.png","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/458704019897061377\/GPLhINBv_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2803191\/1398790022","profile_link_color":"0070C5","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"86C6E3","profile_text_color":"444444","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":70,"favorite_count":47,"entities":{"hashtags":[],"symbols":[],"urls":[{"url":"http:\/\/t.co\/Ha0RzAr8Bn","expanded_url":"http:\/\/intel.ly\/1kwMf49","display_url":"intel.ly\/1kwMf49","indices":[93,115]}],"user_mentions":[],"media":[{"id":462626389146234881,"id_str":"462626389146234881","indices":[116,138],"media_url":"http:\/\/pbs.twimg.com\/media\/BmuUP_TIcAEjJnR.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/BmuUP_TIcAEjJnR.jpg","url":"http:\/\/t.co\/Xkwfb2Hh64","display_url":"pic.twitter.com\/Xkwfb2Hh64","expanded_url":"http:\/\/twitter.com\/intel\/status\/462626389251072000\/photo\/1","type":"photo","sizes":{"small":{"w":340,"h":227,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"large":{"w":525,"h":350,"resize":"fit"},"medium":{"w":525,"h":350,"resize":"fit"}}}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"created_at":"Fri May 02 23:45:00 +0000 2014","id":462377247161470977,"id_str":"462377247161470977","text":"Wish your smartphone camera helped you take better selifes? Meet the Zenfone by @ASUS - http:\/\/t.co\/Hu4UVRB8LL http:\/\/t.co\/kVH3CsuEHe","source":"<a href=\"http:\/\/www.sprinklr.com\" rel=\"nofollow\">Sprinklr<\/a>","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2803191,"id_str":"2803191","name":"Intel","screen_name":"intel","location":"\u00dcT: 37.575291,-122.341831","description":"Intel news, views & events about global tech innovation.","url":"http:\/\/t.co\/MYZ7uTo0nG","entities":{"url":{"urls":[{"url":"http:\/\/t.co\/MYZ7uTo0nG","expanded_url":"http:\/\/iq.intel.com","display_url":"iq.intel.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":3072725,"friends_count":1202,"listed_count":9083,"created_at":"Thu Mar 29 07:22:48 +0000 2007","favourites_count":472,"utc_offset":-25200,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":true,"statuses_count":4808,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"FFFFFF","profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/433119978913427457\/_mEcPZWl.jpeg","profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/433119978913427457\/_mEcPZWl.jpeg","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/458704019897061377\/GPLhINBv_normal.png","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/458704019897061377\/GPLhINBv_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2803191\/1398790022","profile_link_color":"0070C5","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"86C6E3","profile_text_color":"444444","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":50,"favorite_count":55,"entities":{"hashtags":[],"symbols":[],"urls":[{"url":"http:\/\/t.co\/Hu4UVRB8LL","expanded_url":"http:\/\/intel.ly\/1kxsoSz","display_url":"intel.ly\/1kxsoSz","indices":[88,110]}],"user_mentions":[{"screen_name":"ASUS","name":"ASUS","id":591646425,"id_str":"591646425","indices":[80,85]}],"media":[{"id":462377247010488322,"id_str":"462377247010488322","indices":[111,133],"media_url":"http:\/\/pbs.twimg.com\/media\/BmqxqAhIgAIalgZ.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/BmqxqAhIgAIalgZ.jpg","url":"http:\/\/t.co\/kVH3CsuEHe","display_url":"pic.twitter.com\/kVH3CsuEHe","expanded_url":"http:\/\/twitter.com\/intel\/status\/462377247161470977\/photo\/1","type":"photo","sizes":{"small":{"w":340,"h":222,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"large":{"w":541,"h":353,"resize":"fit"},"medium":{"w":541,"h":353,"resize":"fit"}}}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"}]';



	$tweet_data = json_decode($json_data,true);
	
	echo "Name: ".$tweet_data[0][user][name]."<br>"; 
	echo "Created on:".$tweet_data[0][created_at]."<br>";
	echo "Tweet: ".$tweet_data[0][text]."<br>";	

Open in new window

Your help has saved me hundreds of hours of internet surfing.
fblack61
SOLUTION
rinfo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
madstylex

ASKER
Thanks rinfo,

I changed the last few lines of my code to the following:


<?php

session_start();
require_once("twitteroauth.php"); //Path to twitteroauth library

$task = $argv[1];
$twitteruser = $argv[2];
$twitterkeyword = $argv[2];
$notweets = $argv[3];
$consumerkey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$consumersecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$accesstoken = "XXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$accesstokensecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

if ($task == "show") {
function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
  $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
  return $connection;
}

$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);

//if ($task == "show") {

$tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$twitteruser."&count=".$notweets);

$json_data = json_encode($tweets);

$tweet_data = json_decode($json_data,true);

$nos_of_tweets = count($tweets);
for($i=0;$i<$nos_of_tweets;$i++){
        echo "Name: ".$tweet_data[$i][user][name]."<br>";
        echo "Created on:".$tweet_data[$i][created_at]."<br>";
        echo "Tweet: ".$tweet_data[$i][text]."<br>";
}

//echo json_encode($tweets);
//echo $tweets;
}

//echo $json_data
?>

Open in new window


I get the following output:


PHP Notice:  Use of undefined constant user - assumed 'user' in /home/cmoncada/scripts/gettweets.php on line 35
PHP Notice:  Use of undefined constant name - assumed 'name' in /home/cmoncada/scripts/gettweets.php on line 35
Name: Intel<br>PHP Notice:  Use of undefined constant created_at - assumed 'created_at' in /home/cmoncada/scripts/gettweets.php on line 36
Created on:Sat May 03 16:15:01 +0000 2014<br>PHP Notice:  Use of undefined constant text - assumed 'text' in /home/cmoncada/scripts/gettweets.php on line 37
Tweet: Ready for travel season? A variety of apps could make tablets the essential travel companion http://t.co/Ha0RzAr8Bn http://t.co/Xkwfb2Hh64<br>PHP Notice:  Use of undefined constant user - assumed 'user' in /home/cmoncada/scripts/gettweets.php on line 35
PHP Notice:  Use of undefined constant name - assumed 'name' in /home/cmoncada/scripts/gettweets.php on line 35
Name: Intel<br>PHP Notice:  Use of undefined constant created_at - assumed 'created_at' in /home/cmoncada/scripts/gettweets.php on line 36
Created on:Fri May 02 23:45:00 +0000 2014<br>PHP Notice:  Use of undefined constant text - assumed 'text' in /home/cmoncada/scripts/gettweets.php on line 37
Tweet: Wish your smartphone camera helped you take better selifes? Meet the Zenfone by @ASUS - http://t.co/Hu4UVRB8LL http://t.co/kVH3CsuEHe<br>

It seems to almost work but i'm not sure where it is going wrong.
rinfo

Just make sure you are getting json file that you have exampled in your post.
To make sure
after this line
$tweet_data = json_decode($json_data,true);
put
print_r($tweet_data);
Now check whether it does have a std object 'user' or not.
or you may submit output here and i can check what could be wrong.
SOLUTION
madstylex

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
rinfo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Ray Paseur

PHP Notice:  Use of undefined constant user - assumed 'user' in /home/cmoncada/scripts/gettweets.php on line 35
This occurs because of the way PHP handles constants, versus the way it handles quoted literal strings in array keys.  This article explains it.  See especially the part about time bombs.
https://www.experts-exchange.com/Programming/Languages/Scripting/PHP/A_12241-Quotation-Marks-in-PHP.html

If you're new to PHP and want to get started learning how the language works, this article may be helpful:
https://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Ray Paseur

There is no "username" in the JSON string.  I used the screen name instead.
http://iconoun.com/demo/temp_madstylex.php

<?php // demo/temp_madstylex.php
error_reporting(E_ALL);

/**
 * SEE http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28425913.html#a40041192
 *
 * username
 * 'date and time' 'tweet'
 */

// JSON IS ALWAYS UTF-8
echo '<meta charset="utf-8" />' . PHP_EOL;

// TEST DATA FROM THE POST AT EE
$jso = <<<EOD
[{"created_at":"Sat May 03 16:15:01 +0000 2014","id":462626389251072000,"id_str":"462626389251072000","text":"Ready for travel season? A variety of apps could make tablets the essential travel companion http:\/\/t.co\/Ha0RzAr8Bn http:\/\/t.co\/Xkwfb2Hh64","source":"<a href=\"http:\/\/www.sprinklr.com\" rel=\"nofollow\">Sprinklr<\/a>","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2803191,"id_str":"2803191","name":"Intel","screen_name":"intel","location":"\u00dcT: 37.575291,-122.341831","description":"Intel news, views & events about global tech innovation.","url":"http:\/\/t.co\/MYZ7uTo0nG","entities":{"url":{"urls":[{"url":"http:\/\/t.co\/MYZ7uTo0nG","expanded_url":"http:\/\/iq.intel.com","display_url":"iq.intel.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":3072725,"friends_count":1202,"listed_count":9083,"created_at":"Thu Mar 29 07:22:48 +0000 2007","favourites_count":472,"utc_offset":-25200,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":true,"statuses_count":4808,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"FFFFFF","profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/433119978913427457\/_mEcPZWl.jpeg","profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/433119978913427457\/_mEcPZWl.jpeg","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/458704019897061377\/GPLhINBv_normal.png","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/458704019897061377\/GPLhINBv_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2803191\/1398790022","profile_link_color":"0070C5","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"86C6E3","profile_text_color":"444444","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":70,"favorite_count":47,"entities":{"hashtags":[],"symbols":[],"urls":[{"url":"http:\/\/t.co\/Ha0RzAr8Bn","expanded_url":"http:\/\/intel.ly\/1kwMf49","display_url":"intel.ly\/1kwMf49","indices":[93,115]}],"user_mentions":[],"media":[{"id":462626389146234881,"id_str":"462626389146234881","indices":[116,138],"media_url":"http:\/\/pbs.twimg.com\/media\/BmuUP_TIcAEjJnR.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/BmuUP_TIcAEjJnR.jpg","url":"http:\/\/t.co\/Xkwfb2Hh64","display_url":"pic.twitter.com\/Xkwfb2Hh64","expanded_url":"http:\/\/twitter.com\/intel\/status\/462626389251072000\/photo\/1","type":"photo","sizes":{"small":{"w":340,"h":227,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"large":{"w":525,"h":350,"resize":"fit"},"medium":{"w":525,"h":350,"resize":"fit"}}}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"},{"created_at":"Fri May 02 23:45:00 +0000 2014","id":462377247161470977,"id_str":"462377247161470977","text":"Wish your smartphone camera helped you take better selifes? Meet the Zenfone by @ASUS - http:\/\/t.co\/Hu4UVRB8LL http:\/\/t.co\/kVH3CsuEHe","source":"<a href=\"http:\/\/www.sprinklr.com\" rel=\"nofollow\">Sprinklr<\/a>","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2803191,"id_str":"2803191","name":"Intel","screen_name":"intel","location":"\u00dcT: 37.575291,-122.341831","description":"Intel news, views & events about global tech innovation.","url":"http:\/\/t.co\/MYZ7uTo0nG","entities":{"url":{"urls":[{"url":"http:\/\/t.co\/MYZ7uTo0nG","expanded_url":"http:\/\/iq.intel.com","display_url":"iq.intel.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":3072725,"friends_count":1202,"listed_count":9083,"created_at":"Thu Mar 29 07:22:48 +0000 2007","favourites_count":472,"utc_offset":-25200,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":true,"statuses_count":4808,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"FFFFFF","profile_background_image_url":"http:\/\/pbs.twimg.com\/profile_background_images\/433119978913427457\/_mEcPZWl.jpeg","profile_background_image_url_https":"https:\/\/pbs.twimg.com\/profile_background_images\/433119978913427457\/_mEcPZWl.jpeg","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/458704019897061377\/GPLhINBv_normal.png","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/458704019897061377\/GPLhINBv_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2803191\/1398790022","profile_link_color":"0070C5","profile_sidebar_border_color":"FFFFFF","profile_sidebar_fill_color":"86C6E3","profile_text_color":"444444","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":50,"favorite_count":55,"entities":{"hashtags":[],"symbols":[],"urls":[{"url":"http:\/\/t.co\/Hu4UVRB8LL","expanded_url":"http:\/\/intel.ly\/1kxsoSz","display_url":"intel.ly\/1kxsoSz","indices":[88,110]}],"user_mentions":[{"screen_name":"ASUS","name":"ASUS","id":591646425,"id_str":"591646425","indices":[80,85]}],"media":[{"id":462377247010488322,"id_str":"462377247010488322","indices":[111,133],"media_url":"http:\/\/pbs.twimg.com\/media\/BmqxqAhIgAIalgZ.jpg","media_url_https":"https:\/\/pbs.twimg.com\/media\/BmqxqAhIgAIalgZ.jpg","url":"http:\/\/t.co\/kVH3CsuEHe","display_url":"pic.twitter.com\/kVH3CsuEHe","expanded_url":"http:\/\/twitter.com\/intel\/status\/462377247161470977\/photo\/1","type":"photo","sizes":{"small":{"w":340,"h":222,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"large":{"w":541,"h":353,"resize":"fit"},"medium":{"w":541,"h":353,"resize":"fit"}}}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"}]
EOD;

// MAKE AN ARRAY/OBJECT FROM THE JSON STRING
$dat = json_decode($jso);

/* ACTIVATE THIS TO VISUALIZE THE DATA
echo '<pre>' . PHP_EOL;
var_dump($dat);
echo '</pre>' . PHP_EOL;
*/


// ITERATE OVER THE ARRAY OF OBJECTS
foreach ($dat as $obj)
{
    // EXTRACT THE DATA ELEMENTS WE WANT
    $when = $obj->created_at;
    $text = $obj->text;
    $name = $obj->user->screen_name;

    // SHOW THE WORK PRODUCT
    echo PHP_EOL;
    echo '<p>';
    echo $name;
    echo '<br>';
    echo "$when $text";
    echo '</p>';
}

Open in new window

HTH.   Please post back if you have any questions, ~Ray
madstylex

ASKER
I quoted out the array keys