Printing a specific value in array PHP - php

I want to output the value of followers_count just once. I managed to this using a foreach loop, however this obviously outputted the result for multiple times. Is there some other simple way I can do this?
the array is declared as follows:
$tweetsshow = $connection->get("https://api.twitter.com/1.1/users/show.json?screen_name=".$twitteruser);
echo $tweetsshow[0]->user->followers_count;
array(30) {
[0]=>
object(stdClass)#5 (24) {
["created_at"]=>
string(30) "Wed May 20 12:32:30 +0000 2015"
["id"]=>
float(6.010025574446E+17)
["id_str"]=>
string(18) "601002557444595712"
["text"]=>
string(79) "Judge Farrugia Sacco loses appeal http://t.co/njcgvTDTej http://t.co/GRjnBt13uC"
["source"]=>
string(71) "Times of Malta"
["truncated"]=>
bool(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"]=>
object(stdClass)#6 (39) {
["id"]=>
int(390687940)
["id_str"]=>
string(9) "390687940"
["name"]=>
string(14) "Times of Malta"
["screen_name"]=>
string(15) "TheTimesofMalta"
["location"]=>
string(5) "Malta"
["description"]=>
string(74) "General, sporting, and business news for Malta and the surrounding region."
["url"]=>
string(22) "http://t.co/OYjxN0Y4tX"
["description"]=>
object(stdClass)#10 (1) {
["urls"]=>
array(0) {
}
}
}
["protected"]=>
bool(false)
["followers_count"]=>
int(13865)
["friends_count"]=>
int(13)
["listed_count"]=>
int(153)
["created_at"]=>
string(30) "Fri Oct 14 11:20:15 +0000 2011"
["favourites_count"]=>
int(0)

You can just simply do:
echo $array[0]->user->followers_count; //Returns 13865

Related

Php Json get first element info

so I'm using a PHP Twitter API to grab a list of tweets with a certain hashtag. I'm looking to get the following info from the returned json; 'screen_name' and 'text'.
The screen_name is on line 44 and the text is on line 20.
Here is the json output.
object(stdClass)#5 (2) {
["statuses"]=>
array(15) {
[0]=>
object(stdClass)#6 (24) {
["metadata"]=>
object(stdClass)#7 (2) {
["iso_language_code"]=>
string(2) "en"
["result_type"]=>
string(6) "recent"
}
["created_at"]=>
string(30) "Fri Dec 05 21:22:00 +0000 2014"
["id"]=>
float(5.4097942452372E+17)
["id_str"]=>
string(18) "540979424523718656"
["text"]=>
string(100) "Shits getting real. Crit happens tonight. #dnd #dungeonsanddragons #nerd #rpg http://t.co/44Lnrmmfte"
["source"]=>
string(59) "Instagram"
["truncated"]=>
bool(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"]=>
object(stdClass)#8 (41) {
["id"]=>
int(1297196190)
["id_str"]=>
string(10) "1297196190"
["name"]=>
string(12) "Brandon Wade"
["screen_name"]=>
string(15) "Brandonus_Prime"
["location"]=>
string(15) "The woods of NC"
["profile_location"]=>
NULL
["description"]=>
string(29) "If it bleeds, we can kill it."
["url"]=>
string(22) "http://t.co/EkGUdm9yDO"
["entities"]=>
object(stdClass)#9 (2) {
["url"]=>
object(stdClass)#10 (1) {
["urls"]=>
array(1) {
[0]=>
object(stdClass)#11 (4) {
["url"]=>
string(22) "http://t.co/EkGUdm9yDO"
["expanded_url"]=>
string(34) "http://facebook.com/brandonusprime"
["display_url"]=>
string(27) "facebook.com/brandonusprime"
["indices"]=>
array(2) {
[0]=>
int(0)
[1]=>
int(22)
}
}
}
}
["description"]=>
object(stdClass)#12 (1) {
["urls"]=>
array(0) {
}
}
}
["protected"]=>
bool(false)
["followers_count"]=>
int(44)
["friends_count"]=>
int(246)
["listed_count"]=>
int(0)
["created_at"]=>
string(30) "Mon Mar 25 01:10:47 +0000 2013"
["favourites_count"]=>
int(18)
["utc_offset"]=>
NULL
["time_zone"]=>
NULL
["geo_enabled"]=>
bool(false)
["verified"]=>
bool(false)
["statuses_count"]=>
int(170)
["lang"]=>
string(2) "en"
["contributors_enabled"]=>
bool(false)
["is_translator"]=>
bool(false)
["is_translation_enabled"]=>
bool(false)
["profile_background_color"]=>
string(6) "C0DEED"
["profile_background_image_url"]=>
string(48) "http://abs.twimg.com/images/themes/theme1/bg.png"
["profile_background_image_url_https"]=>
string(49) "https://abs.twimg.com/images/themes/theme1/bg.png"
["profile_background_tile"]=>
bool(false)
["profile_image_url"]=>
string(99) "http://pbs.twimg.com/profile_images/378800000698263057/6592d36cf8e2beb02c9f3ee9abf4fdd7_normal.jpeg"
["profile_image_url_https"]=>
string(100) "https://pbs.twimg.com/profile_images/378800000698263057/6592d36cf8e2beb02c9f3ee9abf4fdd7_normal.jpeg"
["profile_banner_url"]=>
string(59) "https://pbs.twimg.com/profile_banners/1297196190/1364236862"
["profile_link_color"]=>
string(6) "0084B4"
["profile_sidebar_border_color"]=>
string(6) "C0DEED"
["profile_sidebar_fill_color"]=>
string(6) "DDEEF6"
["profile_text_color"]=>
string(6) "333333"
["profile_use_background_image"]=>
bool(true)
["default_profile"]=>
bool(true)
["default_profile_image"]=>
bool(false)
["following"]=>
bool(false)
["follow_request_sent"]=>
bool(false)
["notifications"]=>
bool(false)
}
["geo"]=>
NULL
["coordinates"]=>
NULL
["place"]=>
NULL
["contributors"]=>
NULL
["retweet_count"]=>
int(0)
["favorite_count"]=>
int(0)
["entities"]=>
object(stdClass)#13 (4) {
["hashtags"]=>
array(4) {
[0]=>
object(stdClass)#14 (2) {
["text"]=>
string(3) "dnd"
["indices"]=>
array(2) {
[0]=>
int(42)
[1]=>
int(46)
}
}
[1]=>
object(stdClass)#15 (2) {
["text"]=>
string(18) "dungeonsanddragons"
["indices"]=>
array(2) {
[0]=>
int(47)
[1]=>
int(66)
}
}
[2]=>
object(stdClass)#16 (2) {
["text"]=>
string(4) "nerd"
["indices"]=>
array(2) {
[0]=>
int(67)
[1]=>
int(72)
}
}
[3]=>
object(stdClass)#17 (2) {
["text"]=>
string(3) "rpg"
["indices"]=>
array(2) {
[0]=>
int(73)
[1]=>
int(77)
}
}
}
["symbols"]=>
array(0) {
}
["user_mentions"]=>
array(0) {
}
["urls"]=>
array(1) {
[0]=>
object(stdClass)#18 (4) {
["url"]=>
string(22) "http://t.co/44Lnrmmfte"
["expanded_url"]=>
string(34) "http://instagram.com/p/wPV3gmr1kl/"
["display_url"]=>
string(27) "instagram.com/p/wPV3gmr1kl/"
["indices"]=>
array(2) {
[0]=>
int(78)
[1]=>
int(100)
}
}
}
}
["favorited"]=>
bool(false)
["retweeted"]=>
bool(false)
["possibly_sensitive"]=>
bool(false)
["lang"]=>
string(2) "en"
}
}
Here is my PHP Code
<?php
require_once 'twitteroauth/twitteroauth.php';
define('CONSUMER_KEY', '');
define('CONSUMER_SECRET', '');
define('ACCESS_TOKEN', '-');
define('ACCESS_TOKEN_SECRET', '');
$toa = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$query = array(
"q" => "#nerd",
"result_type" => "recent"
);
$results = $toa->get('search/tweets', $query);
var_dump($results); die();
foreach ($results->statuses as $result) {
echo $result->user->screen_name . ": " . $result->text . "<br>";
}
Thanks a ton! I've been trying for a while and need some pointing in the right direction :)

Exclude Retweets in Twitter Search API 1.1

Here I'm trying to retrieve the tweets which has the tag 'V57' using search api 1.1. Dumped & seen the results of search term by using,
$search_tim = $connection->get('search/tweets',array('q' => ' #V57', 'count' => 5, 'result_type' => 'recent'));
This is the result after doing var_dump :
object(stdClass)#10 (2) {
["statuses"]=>
array(5) {
[0]=>
object(stdClass)#11 (25) {
["metadata"]=>
object(stdClass)#12 (2) {
["result_type"]=>
string(6) "recent"
["iso_language_code"]=>
string(2) "en"
}
["created_at"]=>
string(30) "Wed Feb 12 16:26:35 +0000 2014"
["id"]=>
float(4.33638273555E+17)
["id_str"]=>
string(18) "4336382731354561"
["text"]=>
string(131) "RT #useracc: Plz consult a doctor #V57"
["source"]=>
string(84) "Twitter for Android"
["truncated"]=>
bool(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"]=>
object(stdClass)#13 (40) {
["id"]=>
int(965892252)
["id_str"]=>
string(9) "965892252"
["name"]=>
string(10) "khan"
["screen_name"]=>
string(10) "khan"
["location"]=>
string(0) ""
["url"]=>
NULL
["entities"]=>
object(stdClass)#14 (1) {
["description"]=>
object(stdClass)#15 (1) {
["urls"]=>
array(0) {
}
}
}
["protected"]=>
bool(false)
["followers_count"]=>
int(457)
["friends_count"]=>
int(500)
["listed_count"]=>
int(3)
["created_at"]=>
string(30) "Fri Nov 23 10:56:08 +0000 2012"
["favourites_count"]=>
int(129)
["utc_offset"]=>
int(19800)
["time_zone"]=>
string(7) "Chennai"
["geo_enabled"]=>
bool(false)
["verified"]=>
bool(false)
["statuses_count"]=>
int(3230)
["lang"]=>
string(2) "en"
["contributors_enabled"]=>
bool(false)
["is_translator"]=>
bool(false)
["is_translation_enabled"]=>
bool(false)
["profile_background_color"]=>
string(6) "0099B9"
["profile_background_image_url"]=>
string(48) "http://abs.twimg.com/images/themes/theme4/bg.gif"
["profile_background_image_url_https"]=>
string(49) "https://abs.twimg.com/images/themes/theme4/bg.gif"
["profile_background_tile"]=>
bool(false)
["profile_image_url"]=>
string(99) "http://pbs.twimg.com/profile_images/3788093993/0639a4b8297f9eea2cbb9de89f5c3a40_normal.jpeg"
["profile_image_url_https"]=>
string(100) "https://pbs.twimg.com/profile_images/37883993/0639a4b8297f9eea2cbb95c3a40_normal.jpeg"
["profile_banner_url"]=>
string(58) "https://pbs.twimg.com/profile_banners/9658922/1386619"
["profile_link_color"]=>
string(6) "0099B9"
["profile_sidebar_border_color"]=>
string(6) "5ED4DC"
["profile_sidebar_fill_color"]=>
string(6) "95E8EC"
["profile_text_color"]=>
string(6) "3C3940"
["profile_use_background_image"]=>
bool(true)
["default_profile"]=>
bool(false)
["default_profile_image"]=>
bool(false)
["following"]=>
bool(false)
["follow_request_sent"]=>
bool(false)
["notifications"]=>
bool(false)
}
["geo"]=>
NULL
["coordinates"]=>
NULL
["place"]=>
NULL
["contributors"]=>
NULL
["retweeted_status"]=>
object(stdClass)#16 (24) {
["metadata"]=>
object(stdClass)#17 (2) {
["result_type"]=>
string(6) "recent"
["iso_language_code"]=>
string(2) "en"
}
["created_at"]=>
string(30) "Wed Feb 12 15:33:36 +0000 2014"
["id"]=>
float(4.3362493936345E+17)
["id_str"]=>
string(18) "43362493446784"
["source"]=>
string(84) "Twitter for Android"
["truncated"]=>
bool(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"]=>
object(stdClass)#18 (40) {
["id"]=>
int(168362964)
["id_str"]=>
string(9) "168362964"
["name"]=>
string(5) "usracc"
["screen_name"]=>
string(12) "useracc"
["location"]=>
string(16) "India."
["url"]=>
NULL
["entities"]=>
object(stdClass)#19 (1) {
["description"]=>
object(stdClass)#20 (1) {
["urls"]=>
array(0) {
}
}
}
["protected"]=>
bool(false)
["followers_count"]=>
int(651)
["friends_count"]=>
int(197)
["listed_count"]=>
int(6)
["created_at"]=>
string(30) "Mon Jul 19 03:54:15 +0000 2010"
["favourites_count"]=>
int(4267)
["utc_offset"]=>
int(19800)
["time_zone"]=>
string(7) "Chennai"
["geo_enabled"]=>
bool(true)
["verified"]=>
bool(false)
["statuses_count"]=>
int(10177)
["lang"]=>
string(2) "en"
["contributors_enabled"]=>
bool(false)
["is_translator"]=>
bool(false)
["is_translation_enabled"]=>
bool(false)
["profile_background_color"]=>
string(6) "C0DEED"
["profile_background_image_url"]=>
string(48) "http://abs.twimg.com/images/themes/theme1/bg.png"
["profile_background_image_url_https"]=>
string(49) "https://abs.twimg.com/images/themes/theme1/bg.png"
["profile_background_tile"]=>
bool(false)
["profile_image_url"]=>
string(75) "http://pbs.twimg.com/profile_images/4338561184/quFHKeYq_normal.jpeg"
["profile_image_url_https"]=>
string(76) "https://pbs.twimg.com/profile_images/433856131184/quFHKeYq_normal.jpeg"
["profile_banner_url"]=>
string(58) "https://pbs.twimg.com/profile_banners/168364/1392170036"
["profile_link_color"]=>
string(6) "0084B4"
["profile_sidebar_border_color"]=>
string(6) "C0DEED"
["profile_sidebar_fill_color"]=>
string(6) "DDEEF6"
["profile_text_color"]=>
string(6) "333333"
["profile_use_background_image"]=>
bool(true)
["default_profile"]=>
bool(true)
["default_profile_image"]=>
bool(false)
["following"]=>
bool(false)
["follow_request_sent"]=>
bool(false)
["notifications"]=>
bool(false)
}
["geo"]=>
NULL
["coordinates"]=>
NULL
["place"]=>
NULL
["contributors"]=>
NULL
["retweet_count"]=>
int(5)
["favorite_count"]=>
int(10)
["entities"]=>
object(stdClass)#21 (5) {
["hashtags"]=>
array(1) {
[0]=>
object(stdClass)#22 (2) {
["text"]=>
string(7) "v57"
["indices"]=>
array(2) {
[0]=>
int(76)
[1]=>
int(84)
}
}
}
["symbols"]=>
array(0) {
}
["urls"]=>
array(0) {
}
["favorited"]=>
bool(false)
["retweeted"]=>
bool(false)
["possibly_sensitive"]=>
bool(false)
["lang"]=>
string(2) "en"
}
["retweet_count"]=>
int(5)
["favorite_count"]=>
int(0)
Now, i would like to retrieve the original tweets alone which has V57 tag by ignoring all Retweets similar to this
string(131) "RT #useravv: Plz consult a doctor #V57"
I've googled and found this thread. But it was old API version.
My Doubt has been cleared. Thanks to the SO user Newbi3 :)
Here is a way to exclude Retweets in Search api 1.1
$search_tim = $connection->get('search/tweets',array('q' => ' #V57 -RT', 'count' => 5,'result_type' => 'recent'));
Adding -RT at the end of search term will filter it.
EDIT :
The above approach will simply eliminate the tweet too if they included #RT is in their status and username or screename. This will blindly ignore tweets when its sees RT. This is a temporary solution.
The permanent solution is, get the RT status & if if its retweet simply assign a value like 1 to a variable & 0 if its original. Eg..
if (isset($tweet_object->retweeted_status)) {
// This is a retweet
// Use the original tweet's entities, they are more complete
$entities = $tweet_object->retweeted_status->entities;
$is_rt = 1; // Set 1 if retweeted
} else {
$entities = $tweet_object->entities;
$is_rt = 0; // Set 0 if original
}
Then just do like,
if($is_rt==0) // if its a original tweet
{
...
....
}
I have found concatenating "-filter:retweets" to the end of your query string works best.
If you simply add -RT you might run into issues with accidentally filtering tweets containing "RT" for example "Russia Today" will use that string quite a lot!
The following pages describe Twitter search operators:
https://support.twitter.com/articles/71577-using-advanced-search
http://thesocialchic.com/2013/04/26/how-to-master-twitter-search/

Milti dimentional XML parsing: Getting values using PHP

var_dump result after parsing the XML is
array(2) {
["link"]=>
object(SimpleXMLElement)#3 (1) {
[0]=>
string(24) "http://www.domain.com"
}
["items"]=>
array(10) {
[0]=>
object(SimpleXMLElement)#4 (9) {
["title"]=>
string(32) "The Car Pro Show 4-20-13 Hour 1"
["link"]=>
string(131) "http://www.domain.com/the-car-pro-show-4-20-13-hour-1?utm_source=rss&utm_medium=rss&utm_campaign=the-car-pro-show-4-20-13-hour-1"
["comments"]=>
string(65) "http://www.domain.com/the-car-pro-show-4-20-13-hour-1#comments"
["pubDate"]=>
string(31) "Sat, 20 Apr 2013 19:47:08 +0000"
["category"]=>
object(SimpleXMLElement)#2 (0) {
}
["guid"]=>
string(33) "http://www.domain.com/?p=11118"
["description"]=>
string(89) "… Read moreThe post The Car Pro Show 4-20-13 Hour 1 appeared first on Car Pro USA."
["enclosure"]=>
object(SimpleXMLElement)#14 (1) {
["#attributes"]=>
array(3) {
["url"]=>
string(68) "http://www.domain.com/wp-content/uploads/2013/04/42013-Hour-1.mp3"
["length"]=>
string(8) "37202230"
["type"]=>
string(10) "audio/mpeg"
}
}
["updated"]=>
string(10) "4 days ago"
}
[1]=>
object(SimpleXMLElement)#5 (9) {
["title"]=>
string(32) "The Car Pro Show 4-20-13 Hour 2"
["link"]=>
string(131) "http://www.domain.com/the-car-pro-show-4-20-13-hour-2?utm_source=rss&utm_medium=rss&utm_campaign=the-car-pro-show-4-20-13-hour-2"
["comments"]=>
string(65) "http://www.domain.com/the-car-pro-show-4-20-13-hour-2#comments"
["pubDate"]=>
string(31) "Sat, 20 Apr 2013 19:45:46 +0000"
["category"]=>
object(SimpleXMLElement)#14 (0) {
}
["guid"]=>
string(33) "http://www.domain.com/?p=11116"
["description"]=>
string(89) "… Read moreThe post The Car Pro Show 4-20-13 Hour 2 appeared first on Car Pro USA."
["enclosure"]=>
object(SimpleXMLElement)#2 (1) {
["#attributes"]=>
array(3) {
["url"]=>
string(68) "http://www.domain.com/wp-content/uploads/2013/04/42013-Hour-2.mp3"
["length"]=>
string(8) "37151773"
["type"]=>
string(10) "audio/mpeg"
}
}
["updated"]=>
string(10) "4 days ago"
}
[2]=>
object(SimpleXMLElement)#6 (9) {
["title"]=>
string(32) "The Car Pro Show 4-20-13 Hour 3"
["link"]=>
string(131) "http://www.domain.com/the-car-pro-show-4-20-13-hour-3?utm_source=rss&utm_medium=rss&utm_campaign=the-car-pro-show-4-20-13-hour-3"
["comments"]=>
string(65) "http://www.domain.com/the-car-pro-show-4-20-13-hour-3#comments"
["pubDate"]=>
string(31) "Sat, 20 Apr 2013 19:44:28 +0000"
["category"]=>
object(SimpleXMLElement)#2 (0) {
}
["guid"]=>
string(33) "http://www.domain.com/?p=11114"
["description"]=>
string(89) "… Read moreThe post The Car Pro Show 4-20-13 Hour 3 appeared first on Car Pro USA."
["enclosure"]=>
object(SimpleXMLElement)#14 (1) {
["#attributes"]=>
array(3) {
["url"]=>
string(68) "http://www.domain.com/wp-content/uploads/2013/04/42013-Hour-3.mp3"
["length"]=>
string(8) "37135093"
["type"]=>
string(10) "audio/mpeg"
}
}
["updated"]=>
string(10) "4 days ago"
}
[3]=>
object(SimpleXMLElement)#7 (9) {
["title"]=>
string(37) "The Car Pro Show 4-20-13 Network Feed"
["link"]=>
string(143) "http://www.domain.com/the-car-pro-show-4-20-13-network-feed?utm_source=rss&utm_medium=rss&utm_campaign=the-car-pro-show-4-20-13-network-feed"
["comments"]=>
string(71) "http://www.domain.com/the-car-pro-show-4-20-13-network-feed#comments"
["pubDate"]=>
string(31) "Sat, 20 Apr 2013 19:27:54 +0000"
["category"]=>
object(SimpleXMLElement)#14 (0) {
}
["guid"]=>
string(33) "http://www.domain.com/?p=11109"
["description"]=>
string(94) "… Read moreThe post The Car Pro Show 4-20-13 Network Feed appeared first on Car Pro USA."
["enclosure"]=>
object(SimpleXMLElement)#2 (1) {
["#attributes"]=>
array(3) {
["url"]=>
string(61) "http://www.domain.com/wp-content/uploads/2013/04/42013.mp3"
["length"]=>
string(8) "84805120"
["type"]=>
string(10) "audio/mpeg"
}
}
["updated"]=>
string(10) "4 days ago"
}
[4]=>
object(SimpleXMLElement)#8 (9) {
["title"]=>
string(32) "The Car Pro Show 4-13-13 Hour 1"
["link"]=>
string(131) "http://www.domain.com/the-car-pro-show-4-13-13-hour-1?utm_source=rss&utm_medium=rss&utm_campaign=the-car-pro-show-4-13-13-hour-1"
["comments"]=>
string(65) "http://www.domain.com/the-car-pro-show-4-13-13-hour-1#comments"
["pubDate"]=>
string(31) "Sat, 13 Apr 2013 19:48:44 +0000"
["category"]=>
object(SimpleXMLElement)#2 (0) {
}
["guid"]=>
string(33) "http://www.domain.com/?p=10968"
["description"]=>
string(89) "… Read moreThe post The Car Pro Show 4-13-13 Hour 1 appeared first on Car Pro USA."
["enclosure"]=>
object(SimpleXMLElement)#14 (1) {
["#attributes"]=>
array(3) {
["url"]=>
string(68) "http://www.domain.com/wp-content/uploads/2013/04/41313-Hour-1.mp3"
["length"]=>
string(8) "37394467"
["type"]=>
string(10) "audio/mpeg"
}
}
["updated"]=>
string(10) "1 week ago"
}
[5]=>
object(SimpleXMLElement)#9 (9) {
["title"]=>
string(32) "The Car Pro Show 4-13-13 Hour 2"
["link"]=>
string(131) "http://www.domain.com/the-car-pro-show-4-13-13-hour-2?utm_source=rss&utm_medium=rss&utm_campaign=the-car-pro-show-4-13-13-hour-2"
["comments"]=>
string(65) "http://www.domain.com/the-car-pro-show-4-13-13-hour-2#comments"
["pubDate"]=>
string(31) "Sat, 13 Apr 2013 19:47:18 +0000"
["category"]=>
object(SimpleXMLElement)#14 (0) {
}
["guid"]=>
string(33) "http://www.domain.com/?p=10966"
["description"]=>
string(89) "… Read moreThe post The Car Pro Show 4-13-13 Hour 2 appeared first on Car Pro USA."
["enclosure"]=>
object(SimpleXMLElement)#2 (1) {
["#attributes"]=>
array(3) {
["url"]=>
string(68) "http://www.domain.com/wp-content/uploads/2013/04/41313-Hour-2.mp3"
["length"]=>
string(8) "37177627"
["type"]=>
string(10) "audio/mpeg"
}
}
["updated"]=>
string(10) "1 week ago"
}
[6]=>
object(SimpleXMLElement)#10 (9) {
["title"]=>
string(32) "The Car Pro Show 4-13-13 Hour 3"
["link"]=>
string(131) "http://www.domain.com/the-car-pro-show-4-13-13-hour-3?utm_source=rss&utm_medium=rss&utm_campaign=the-car-pro-show-4-13-13-hour-3"
["comments"]=>
string(65) "http://www.domain.com/the-car-pro-show-4-13-13-hour-3#comments"
["pubDate"]=>
string(31) "Sat, 13 Apr 2013 19:45:55 +0000"
["category"]=>
object(SimpleXMLElement)#2 (0) {
}
["guid"]=>
string(33) "http://www.domain.com/?p=10964"
["description"]=>
string(89) "… Read moreThe post The Car Pro Show 4-13-13 Hour 3 appeared first on Car Pro USA."
["enclosure"]=>
object(SimpleXMLElement)#14 (1) {
["#attributes"]=>
array(3) {
["url"]=>
string(68) "http://www.domain.com/wp-content/uploads/2013/04/41313-Hour-3.mp3"
["length"]=>
string(8) "36899488"
["type"]=>
string(10) "audio/mpeg"
}
}
["updated"]=>
string(10) "1 week ago"
}
[7]=>
object(SimpleXMLElement)#11 (9) {
["title"]=>
string(38) "The Car Pro Show Network Feed 4-13-13"
["link"]=>
string(143) "http://www.domain.com/the-car-pro-show-network-feed-4-13-13?utm_source=rss&utm_medium=rss&utm_campaign=the-car-pro-show-network-feed-4-13-13"
["comments"]=>
string(71) "http://www.domain.com/the-car-pro-show-network-feed-4-13-13#comments"
["pubDate"]=>
string(31) "Sat, 13 Apr 2013 19:17:07 +0000"
["category"]=>
object(SimpleXMLElement)#14 (0) {
}
["guid"]=>
string(33) "http://www.domain.com/?p=10958"
["description"]=>
string(95) "… Read moreThe post The Car Pro Show Network Feed 4-13-13 appeared first on Car Pro USA."
["enclosure"]=>
object(SimpleXMLElement)#2 (1) {
["#attributes"]=>
array(3) {
["url"]=>
string(61) "http://www.domain.com/wp-content/uploads/2013/04/41313.mp3"
["length"]=>
string(8) "83924992"
["type"]=>
string(10) "audio/mpeg"
}
}
["updated"]=>
string(10) "1 week ago"
}
[8]=>
object(SimpleXMLElement)#12 (9) {
["title"]=>
string(31) "The Car Pro Show Hour 1 4-6-13"
["link"]=>
string(129) "http://www.domain.com/the-car-pro-show-hour-1-4-6-13?utm_source=rss&utm_medium=rss&utm_campaign=the-car-pro-show-hour-1-4-6-13"
["comments"]=>
string(64) "http://www.domain.com/the-car-pro-show-hour-1-4-6-13#comments"
["pubDate"]=>
string(31) "Sat, 06 Apr 2013 19:45:57 +0000"
["category"]=>
object(SimpleXMLElement)#2 (0) {
}
["guid"]=>
string(33) "http://www.domain.com/?p=10824"
["description"]=>
string(88) "… Read moreThe post The Car Pro Show Hour 1 4-6-13 appeared first on Car Pro USA."
["enclosure"]=>
object(SimpleXMLElement)#14 (1) {
["#attributes"]=>
array(3) {
["url"]=>
string(67) "http://www.domain.com/wp-content/uploads/2013/04/4613-Hour-1.mp3"
["length"]=>
string(8) "37239760"
["type"]=>
string(10) "audio/mpeg"
}
}
["updated"]=>
string(11) "2 weeks ago"
}
[9]=>
object(SimpleXMLElement)#13 (9) {
["title"]=>
string(31) "The Car Pro Show Hour 2 4-6-13"
["link"]=>
string(129) "http://www.domain.com/the-car-pro-show-hour-2-4-6-13?utm_source=rss&utm_medium=rss&utm_campaign=the-car-pro-show-hour-2-4-6-13"
["comments"]=>
string(64) "http://www.domain.com/the-car-pro-show-hour-2-4-6-13#comments"
["pubDate"]=>
string(31) "Sat, 06 Apr 2013 19:44:42 +0000"
["category"]=>
object(SimpleXMLElement)#14 (0) {
}
["guid"]=>
string(33) "http://www.domain.com/?p=10822"
["description"]=>
string(88) "… Read moreThe post The Car Pro Show Hour 2 4-6-13 appeared first on Car Pro USA."
["enclosure"]=>
object(SimpleXMLElement)#2 (1) {
["#attributes"]=>
array(3) {
["url"]=>
string(67) "http://www.domain.com/wp-content/uploads/2013/04/4613-Hour-2.mp3"
["length"]=>
string(8) "37202647"
["type"]=>
string(10) "audio/mpeg"
}
}
["updated"]=>
string(11) "2 weeks ago"
}
}
}
I want to get values, like Title, Date & URL. Easily I can retrieve title and date, PHP code is:
<?php foreach($entries['items'] as $entry) { ?>
Title: <?php echo $entry->title; ?>
Date: <?php echo date("M d Y",strtotime($entry->pubDate)); ?>
URL: <?php echo $entry->url ?>
<?php } ?>
But I cannot get value of URL here, how can I get that?
You can get it using attributes() method.
$attrs = $entry->enclosure->attributes();
echo $attrs['url'];

How to access elements from twitter's JSON response? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
From the following response from Twitter, how can I access 'followers_count'?
array(1) {
[0]=> object(stdClass)#1 (21) {
["created_at"]=> string(30) "Mon Oct 15 19:20:28 +0000 2012"
["id"]=> int(257923917879070721)
["id_str"]=> string(18) "257923917879070721"
["text"]=> string(127) "As open enrollment begins, Medicare is getting stronger – but Rep. Ryan wants to dismantle it. My op-ed: http://t.co/DUEYxQOt"
["source"]=> string(3) "web"
["truncated"]=> bool(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"]=> object(stdClass)#2 (38) {
["id"]=> int(16789970)
["id_str"]=> string(8) "16789970"
["name"]=> string(18) "Senator Harry Reid"
["screen_name"]=> string(11) "SenatorReid"
["location"]=> string(15) "Searchlight, NV"
["url"]=> string(22) "http://reid.senate.gov"
["description"]=> string(108) "News from the office of Nevada Senator Harry Reid, the U.S. Senate Majority Leader. (Español: #SenadorReid)"
["protected"]=> bool(false)
["followers_count"]=> int(67261)
["friends_count"]=> int(126)
["listed_count"]=> int(3712)
["created_at"]=> string(30) "Wed Oct 15 19:42:08 +0000 2008"
["favourites_count"]=> int(1)
["utc_offset"]=> int(-18000)
["time_zone"]=> string(5) "Quito"
["geo_enabled"]=> bool(false)
["verified"]=> bool(true)
["statuses_count"]=> int(1556)
["lang"]=> string(2) "en"
["contributors_enabled"]=> bool(false)
["is_translator"]=> bool(false)
["profile_background_color"]=> string(6) "233E6D"
["profile_background_image_url"]=> string(70) "http://a0.twimg.com/profile_background_images/4744650/reid_twitter.jpg"
["profile_background_image_url_https"]=> string(72) "https://si0.twimg.com/profile_background_images/4744650/reid_twitter.jpg"
["profile_background_tile"]=> bool(false)
["profile_image_url"]=> string(66) "http://a0.twimg.com/profile_images/81906216/reid_square_normal.jpg"
["profile_image_url_https"]=> string(68) "https://si0.twimg.com/profile_images/81906216/reid_square_normal.jpg"
["profile_banner_url"]=> string(63) "https://si0.twimg.com/brand_banners/SenatorReid/1323385337/live"
["profile_link_color"]=> string(6) "004CB4"
["profile_sidebar_border_color"]=> string(6) "6383A3"
["profile_sidebar_fill_color"]=> string(6) "AFC4DA"
["profile_text_color"]=> string(6) "333333"
["profile_use_background_image"]=> bool(true)
["default_profile"]=> bool(false)
["default_profile_image"]=> bool(false)
["following"]=> NULL
["follow_request_sent"]=> NULL
["notifications"]=> NULL } ["geo"]=> NULL
["coordinates"]=> NULL
["place"]=> NULL
["contributors"]=> NULL
["retweet_count"]=> int(88)
["entities"]=> object(stdClass)#3 (3) {
["hashtags"]=> array(0) { }
["urls"]=> array(1) {
[0]=> object(stdClass)#4 (4) {
["url"]=> string(20) "http://t.co/DUEYxQOt"
["expanded_url"]=> string(21) "http://huff.to/TshePO"
["display_url"]=> string(14) "huff.to/TshePO"
["indices"]=> array(2) {
[0]=> int(105)
[1]=> int(125)
}
}
}
["user_mentions"]=> array(0) { }
}
["favorited"]=> bool(false)
["retweeted"]=> bool(false)
["possibly_sensitive"]=> bool(false)
}
}
To read easly your var_dump, you can install x-debug : http://xdebug.org/.
And to access at your information, it's :
$followersCount = $twitterResponse[0]->user->followers_count
for your example.
$response[0]["user"]["followers_count"]

php get url from dropbox

I am using the php script dropbox recommended https://github.com/BenTheDesigner, and can get a json response, and also list files.
ie This is an output of files in my developer account from test.php.
This is a list of all files in your [APP] Dropbox.
api_upload_test.txt45 bytes
dsdsdsdsdsdsd0 bytes
ghhhhhhhhhhhh0 bytes
If I Fell - The Beatles.mp31 MB
Koala.jpg762.5 KB
test_download_api_upload_test.txt45 bytes
But I need the absolute url for these files. ie
http://something/sandbox/folder/Koala.jpg
or
http://something/fileget/http://something/koala.jpg
I cannot find anything about specifying a url, or whether I use a dropbox url. Probably a stupid and simple answer.
This is an example of the array;
array(3) {
["code"]=>
string(3) "200"
["body"]=>
object(stdClass)#8 (9) {
["hash"]=>
string(32) "df98863d80aa0c89f5e359a4f3e10b5a"
["thumb_exists"]=>
bool(false)
["bytes"]=>
int(0)
["path"]=>
string(1) "/"
["is_dir"]=>
bool(true)
["size"]=>
string(7) "0 bytes"
["root"]=>
string(10) "app_folder"
["contents"]=>
array(6) {
[0]=>
object(stdClass)#9 (12) {
["revision"]=>
int(1)
["rev"]=>
string(9) "109a31b3c"
["thumb_exists"]=>
bool(false)
["bytes"]=>
int(45)
["modified"]=>
string(31) "Tue, 21 Aug 2012 12:26:04 +0000"
["client_mtime"]=>
string(31) "Tue, 21 Aug 2012 12:26:04 +0000"
["path"]=>
string(20) "/api_upload_test.txt"
["is_dir"]=>
bool(false)
["icon"]=>
string(15) "page_white_text"
["root"]=>
string(7) "dropbox"
["mime_type"]=>
string(10) "text/plain"
["size"]=>
string(8) "45 bytes"
}
[1]=>
object(stdClass)#10 (10) {
["revision"]=>
int(3)
["rev"]=>
string(9) "309a31b3c"
["thumb_exists"]=>
bool(false)
["bytes"]=>
int(0)
["modified"]=>
string(31) "Tue, 21 Aug 2012 14:09:26 +0000"
["path"]=>
string(14) "/dsdsdsdsdsdsd"
["is_dir"]=>
bool(true)
["icon"]=>
string(6) "folder"
["root"]=>
string(7) "dropbox"
["size"]=>
string(7) "0 bytes"
}
[2]=>
object(stdClass)#11 (10) {
["revision"]=>
int(4)
["rev"]=>
string(9) "409a31b3c"
["thumb_exists"]=>
bool(false)
["bytes"]=>
int(0)
["modified"]=>
string(31) "Tue, 21 Aug 2012 15:29:22 +0000"
["path"]=>
string(14) "/ghhhhhhhhhhhh"
["is_dir"]=>
bool(true)
["icon"]=>
string(6) "folder"
["root"]=>
string(7) "dropbox"
["size"]=>
string(7) "0 bytes"
}
Found a way of getting the url. The full path is not given in the array from dropbox. You have to specify media in the request, and the full path is given, which expires every 4 hours.
ie
$media = $dropbox->media($path);

Categories