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'];
Related
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
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
how can I extract the ASIN field from this json code?
This code comes from Amazon API. Actually,I don't know if this code is really a JSON code.
object(stdClass)#6 (2) {
["OperationRequest"]=>
object(stdClass)#7 (4) {
["HTTPHeaders"]=>
object(stdClass)#8 (1) {
["Header"]=>
object(stdClass)#9 (2) {
["Name"]=>
string(9) "UserAgent"
["Value"]=>
string(15) "PHP-SOAP/5.5.22"
}
}
["RequestId"]=>
string(36) "639b29bd-4bad-4b40-8a9a-3bd86df3d876"
["Arguments"]=>
object(stdClass)#10 (1) {
["Argument"]=>
object(stdClass)#11 (2) {
["Name"]=>
string(7) "Service"
["Value"]=>
string(19) "AWSECommerceService"
}
}
["RequestProcessingTime"]=>
float(0.456677)
}
["Items"]=>
object(stdClass)#12 (5) {
["Request"]=>
object(stdClass)#13 (2) {
["IsValid"]=>
string(4) "True"
["ItemSearchRequest"]=>
object(stdClass)#14 (3) {
["Keywords"]=>
string(11) "Bud Spencer"
["ResponseGroup"]=>
string(5) "Small"
["SearchIndex"]=>
string(3) "DVD"
}
}
["TotalResults"]=>
int(598)
["TotalPages"]=>
int(60)
["MoreSearchResultsUrl"]=>
string(232) "http://www.amazon.it/gp/redirect.html?camp=2025&creative=165953&location=http%3A%2F%2Fwww.amazon.it%2Fgp%2Fsearch%3Fkeywords%3DBud%2BSpencer%26url%3Dsearch-alias%253Ddvd&linkCode=sp1&tag=unis04-21&SubscriptionId=AKIAIGBEJI2W275RATZQ"
["Item"]=>
array(10) {
[0]=>
object(stdClass)#15 (3) {
["ASIN"]=>
string(10) "B00OOZTAQ2"
["DetailPageURL"]=>
string(200) "http://www.amazon.it/Bud-Spencer-Collezione-4-Dvd/dp/B00OOZTAQ2%3FSubscriptionId%3DAKIAIGBEJI2W275RATZQ%26tag%3Dunis04-21%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB00OOZTAQ2"
["ItemAttributes"]=>
object(stdClass)#16 (7) {
["Actor"]=>
array(5) {
[0]=>
string(11) "Bud Spencer"
[1]=>
string(11) "Jerry Cala'"
[2]=>
string(16) "Stefano Mingardo"
[3]=>
string(14) "Kallie Knoetze"
[4]=>
string(5) "Gegia"
}
["Author"]=>
array(3) {
[0]=>
string(16) "Marcello Fondato"
[1]=>
string(22) "Francesco Scardamaglia"
[2]=>
string(13) "Rainer Brandt"
}
["Creator"]=>
array(2) {
[0]=>
object(stdClass)#17 (2) {
["_"]=>
string(11) "Bud Spencer"
["Role"]=>
string(19) "Primary Contributor"
}
[1]=>
object(stdClass)#18 (2) {
["_"]=>
string(11) "Jerry Cala'"
["Role"]=>
string(19) "Primary Contributor"
}
}
["Director"]=>
string(12) "Michele Lupo"
["Manufacturer"]=>
string(14) "Eagle Pictures"
["ProductGroup"]=>
string(3) "DVD"
["Title"]=>
string(32) "Bud Spencer - Collezione (4 Dvd)"
}
}
[1]=>
object(stdClass)#19 (3) {
["ASIN"]=>
string(10) "B0036A98ZO"
["DetailPageURL"]=>
string(208) "http://www.amazon.it/Bud-Spencer-Terence-Hill-Monster-Box/dp/B0036A98ZO%3FSubscriptionId%3DAKIAIGBEJI2W275RATZQ%26tag%3Dunis04-21%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB0036A98ZO"
["ItemAttributes"]=>
object(stdClass)#20 (5) {
["Actor"]=>
array(2) {
[0]=>
string(12) "Terence Hill"
[1]=>
string(11) "Bud Spencer"
}
["Creator"]=>
array(2) {
[0]=>
object(stdClass)#21 (2) {
["_"]=>
string(12) "Terence Hill"
["Role"]=>
string(24) "Collaboratore principale"
}
[1]=>
object(stdClass)#22 (2) {
["_"]=>
string(11) "Bud Spencer"
["Role"]=>
string(24) "Collaboratore principale"
}
}
["Manufacturer"]=>
string(26) "3L Vertriebs GmbH & Co. KG"
["ProductGroup"]=>
string(3) "DVD"
["Title"]=>
string(70) "Bud Spencer & Terence Hill - Monster-Box Reloaded [Edizione: Germania]"
}
}
[2]=>
object(stdClass)#23 (3) {
["ASIN"]=>
string(10) "B00HSPBF2M"
["DetailPageURL"]=>
string(200) "http://www.amazon.it/Bud-Spencer-Terence-Hill-Dvd/dp/B00HSPBF2M%3FSubscriptionId%3DAKIAIGBEJI2W275RATZQ%26tag%3Dunis04-21%26linkCode%3Dsp1%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB00HSPBF2M"
["ItemAttributes"]=>
object(stdClass)#24 (7) {
["Actor"]=>
array(5) {
[0]=>
string(17) "Luciano Catenacci"
[1]=>
string(11) "Bud Spencer"
[2]=>
string(12) "Laura Gemser"
[3]=>
string(12) "Terence Hill"
[4]=>
string(9) "Buffy Dee"
}
["Author"]=>
array(6) {
[0]=>
string(12) "Enzo Barboni"
[1]=>
string(14) "Bruno Corbucci"
[2]=>
string(18) "Luciano Vincenzoni"
[3]=>
string(14) "Mario Amendola"
[4]=>
string(17) "Sabatino Ciuffini"
[5]=>
string(15) "Sergio Corbucci"
}
["Creator"]=>
array(2) {
[0]=>
object(stdClass)#25 (2) {
["_"]=>
string(17) "Luciano Catenacci"
["Role"]=>
string(19) "Primary Contributor"
}
[1]=>
object(stdClass)#26 (2) {
["_"]=>
string(11) "Bud Spencer"
["Role"]=>
string(19) "Primary Contributor"
}
}
["Director"]=>
array(3) {
[0]=>
string(12) "Enzo Barboni"
[1]=>
string(15) "Sergio Corbucci"
[2]=>
string(14) "Bruno Corbucci"
}
["Manufacturer"]=>
string(13) "Federal Video"
["ProductGroup"]=>
string(3) "DVD"
["Title"]=>
string(34) "Bud Spencer & Terence Hill (3 Dvd)"
}
}
}
}
}
I have tried to extract ASIN like a normal array and like a JSON object. Help?
Here there is the code I use to generate above code:
try
{
$amazonEcs = new AmazonECS(AWS_API_KEY, AWS_API_SECRET_KEY, 'it', AWS_ASSOCIATE_TAG);
$amazonEcs->associateTag(AWS_ASSOCIATE_TAG);
$response = $amazonEcs->category('DVD')->search("Bud Spencer");
$result=var_dump($response);
}
catch
...
It doesn't seem to be a json message. It seems to be json message print out using PHP. Which language you are going to use to extract the info?
<?php
$json = '{"a":1,"b":2,"c":3}';
//an object of type stdClass
$result = json_decode($json);
echo $result->a, "\r\n";
echo $result->b, "\r\n";
echo $result->c, "\r\n";
//an associative array
$result = json_decode($json, true);
echo $result['a'], "\r\n";
echo $result['b'], "\r\n";
echo $result['c'], "\r\n";
?>
Im having a problem getting my desired output out of a function. I see that its returning the proper data when i do a 'var dump'. However, it either does not show anything or i'm getting invalid argument errors / 'Object of class stdClass could not be converted to string'.
Here is the function
public function searchUser($name, $limit = 0) {
return $this->_makeCall('users/search', false, array('q' => $name, 'count' => $limit));
}
and my code is calling it like this:
$usearch=$_POST['usersearch'];
$result = $instagram->searchUser($usearch);
....
<div id="searchresults">
<h4> Search result for <?php
echo $usearch;
?>
</h4>
<section id="list">
<?php
foreach ($usearch as $object) {
print $object->username;
}
?>
</div>
</div>
lastly, here is the var dump when i just call it that way:
object(stdClass)#2 (2) { ["meta"]=> object(stdClass)#3 (1) { ["code"]=> int(200) } ["data"]=> array(50) { [0]=> object(stdClass)#4 (6) { ["username"]=> string(6) "george" ["bio"]=> string(0) "" ["website"]=> string(0) "" ["profile_picture"]=> string(57) "http://images.ak.instagram.com/profiles/anonymousUser.jpg" ["full_name"]=> string(0) "" ["id"]=> string(7) "7693231" } [1]=> object(stdClass)#5 (6) { ["username"]=> string(9) "instagod7" ["bio"]=> string(28) "Graphic designer 🫠O.D.U." ["website"]=> string(0) "" ["profile_picture"]=> string(76) "http://images.ak.instagram.com/profiles/profile_26017769_75sq_1358524943.jpg" ["full_name"]=> string(6) "George" ["id"]=> string(8) "26017769" } [2]=> object(stdClass)#6 (6) { ["username"]=> string(17) "georgetowncupcake" ["bio"]=> string(81) "Official Instagram account of Georgetown Cupcake | Home of TLC's DC CUPCAKES!" ["website"]=> string(32) "http://www.georgetowncupcake.com" ["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_265095138_75sq_1391136095.jpg" ["full_name"]=> string(18) "Georgetown Cupcake" ["id"]=> string(9) "265095138" } [3]=> object(stdClass)#7 (6) { ["username"]=> string(11) "georgewbush" ["bio"]=> string(79) "43rd President of the United States and Founder of the George W. Bush Institute" ["website"]=> string(21) "http://bushcenter.org" ["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_531790154_75sq_1377896593.jpg" ["full_name"]=> string(14) "George W. Bush" ["id"]=> string(9) "531790154" } [4]=> object(stdClass)#8 (6) { ["username"]=> string(11) "georgelopez" ["bio"]=> string(50) "New Saint George Episode April 10th on #FXNetworks" ["website"]=> string(26) "http://www.georgelopez.com" ["profile_picture"]=> string(76) "http://images.ak.instagram.com/profiles/profile_38811207_75sq_1390655218.jpg" ["full_name"]=> string(12) "George Lopez" ["id"]=> string(8) "38811207" } [5]=> object(stdClass)#9 (6) { ["username"]=> string(14) "georgerauscher" ["bio"]=> string(33) "photography | munich - Impressum:" ["website"]=> string(31) "http://www.george.li/impressum/" ["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_237349510_75sq_1391160241.jpg" ["full_name"]=> string(18) "George A. Rauscher" ["id"]=> string(9) "237349510" }
Presuming the vardump if of the $result variable, the object array you want to iterate is contained within the data property:
foreach ($result->data as $object) {
print $object->username;
}
I have json_decoded my paypal rest api response and gotten this:
["body"]=> object(stdClass)#4 (8) {
["id"]=> string(28) "PAY-66D616332R6551639KJLSMVQ"
["create_time"]=> string(20) "2013-10-10T22:12:38Z"
["update_time"]=> string(20) "2013-10-10T22:12:39Z"
["state"]=> string(7) "created"
["intent"]=> string(4) "sale"
["payer"]=> object(stdClass)#5 (2) {
["payment_method"]=> string(6) "paypal"
["payer_info"]=> object(stdClass)#6 (0) {}
}
["transactions"]=> array(1) {
[0]=> object(stdClass)#7 (3) {
["amount"]=> object(stdClass)#8 (3) {
["total"]=> string(6) "500.85"
["currency"]=> string(3) "USD"
["details"]=> object(stdClass)#9 (2) {
["subtotal"]=> string(6) "460.90"
["shipping"]=> string(5) "39.95"
}
}
["description"]=> string(43) "Mike and Maureen Photography - Order ID #10"
["item_list"]=> object(stdClass)#10 (1) {
["items"]=> array(2) {
[0]=> object(stdClass)#11 (5) {
["name"]=> string(48) "The Bean-8" x 10" - floating frame - black frame"
["sku"]=> string(7) "20 - 13"
["price"]=> string(6) "160.95"
["currency"]=> string(3) "USD"
["quantity"]=> string(1) "1"
}
[1]=> object(stdClass)#12 (5) {
["name"]=> string(62) "40 Steps and a View-36" x 48" - 0.75" thin gallery wrap canvas"
["sku"]=> string(5) "7 - 6"
["price"]=> string(6) "299.95"
["currency"]=> string(3) "USD"
["quantity"]=> string(1) "1"
}
}
}
}
}
["links"]=> array(3) {
[0]=> object(stdClass)#13 (3) {
["href"]=> string(79) "https://api.sandbox.paypal.com/v1/payments/payment/PAY-66D616332R6551639KJLSMVQ"
["rel"]=> string(4) "self"
["method"]=> string(3) "GET"
}
[1]=> object(stdClass)#14 (3) {
["href"]=> string(94) "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-1XB37931V5368954G"
["rel"]=> string(12) "approval_url"
["method"]=> string(8) "REDIRECT"
}
[2]=> object(stdClass)#15 (3) {
["href"]=> string(87) "https://api.sandbox.paypal.com/v1/payments/payment/PAY-66D616332R6551639KJLSMVQ/execute"
["rel"]=> string(7) "execute"
["method"]=> string(4) "POST"
}
}
}
I am trying to check the value of 'state' but I cant seem to figure out how to reference that value. I have tried: ($result is the variable where the array is located)
$result['body']['state']
$result['state']
$body['state']
None of those work, so can anyone tell me how to reference the key 'state' in that mess up there? I am usually pretty good with PHP but for some reason I can not figure this one out.
Thanks for your help.
Edit
I have formatted the response so its easier to ready but I am stuck on selecting the [1] href value. If I base it on the previous example I would use
$result['body']->link but how do I get past that to the specific href in [1]?
The formatting doesn't help, but it looks like $result['body']->state will get you what you're looking for.
You were closest with your first attempt, $result['body']['state'], however $result['body'] is an object, and so you need to use -> to access its properties.
I'm attempting to use the Facebook Graph API to import details from employees Facebook profiles into our personal website.
Fetching the JSON object from the following URI:
https://graph.facebook.com/RDTATTOOANDPIERCING
I thought that I would be able to simply convert to an array and echo the desired value. However I'm getting errors.
Here's the code:
<?php
$facebook = json_decode(file_get_contents("https://graph.facebook.com/RDTATTOOANDPIERCING"));
echo $facebook["about"];
?>
Here's the URL if you want to see the source being rendered:
http://www.rdtattoopiercing.com/
Thanks ahead of time!
json_decode without the second parameter will return an object, if you want an array to be returned add a second parameter TRUE
try this:
$facebook = json_decode(file_get_contents("https://graph.facebook.com/RDTATTOOANDPIERCING"), TRUE);
echo $facebook["about"];
or use object instead if you don't want to add TRUE to the second parameter
$facebook->about;
The problem is that it returned a stdClass not an array, You could tell that by using var_dump($facebook), To convert an stdClass to an array use get_object_vars().
Here is your solution:
<?php
$facebook = get_object_vars(json_decode(file_get_contents("http://graph.facebook.com/RDTATTOOANDPIERCING")));
echo $facebook['about'];
?>
Here is the var_dump before the conversion to an array:
object(stdClass)#1 (20) { ["about"]=> string(60) "Red Dragon Tattoo & Piercing is devoted to inking Cincinnati" ["checkins"]=> int(144) ["description"]=> string(509) "Red Dragon has been open since Feb. 2009, After Gabriel started constructing J began to Fill the chairs with his large following, after only a few months we brought on Chuck and Jocelyn to help with the overwhelming amount of people ready to get tattooed in the Colerain area and we've been inking up Cincinnati since then. We appreciate artfull expressions, and can help you make your own statement to this world through your body. If it's a body piercing, or a tattoo, what better way to express yourself." ["general_info"]=> string(59) "Artists: J, Chuck Hagedorn, Jocelyn Taylor, Gabriel Lowe " ["hours"]=> object(stdClass)#2 (12) { ["mon_1_open"]=> string(5) "13:00" ["mon_1_close"]=> string(5) "20:00" ["tue_1_open"]=> string(5) "13:00" ["tue_1_close"]=> string(5) "20:00" ["wed_1_open"]=> string(5) "13:00" ["wed_1_close"]=> string(5) "20:00" ["thu_1_open"]=> string(5) "13:00" ["thu_1_close"]=> string(5) "20:00" ["fri_1_open"]=> string(5) "13:00" ["fri_1_close"]=> string(5) "20:00" ["sat_1_open"]=> string(5) "13:00" ["sat_1_close"]=> string(5) "20:00" } ["is_published"]=> bool(true) ["location"]=> object(stdClass)#3 (7) { ["street"]=> string(17) "9242 Colerain Ave" ["city"]=> string(10) "Cincinnati" ["state"]=> string(2) "OH" ["country"]=> string(13) "United States" ["zip"]=> string(10) "45251-2406" ["latitude"]=> float(39.239511218398) ["longitude"]=> float(-84.592958873707) } ["parking"]=> object(stdClass)#4 (3) { ["street"]=> int(0) ["lot"]=> int(1) ["valet"]=> int(0) } ["phone"]=> string(17) "+1 (513) 385-6500" ["price_range"]=> string(10) "$$$$ (50+)" ["talking_about_count"]=> int(97) ["username"]=> string(19) "RDTATTOOANDPIERCING" ["website"]=> string(20) "rdtattoopiercing.com" ["were_here_count"]=> int(535) ["category"]=> string(14) "Local business" ["id"]=> string(15) "151284611579488" ["name"]=> string(28) "Red Dragon Tattoo & Piercing" ["link"]=> string(43) "http://www.facebook.com/RDTATTOOANDPIERCING" ["likes"]=> int(835) ["cover"]=> object(stdClass)#5 (3) { ["cover_id"]=> float(4.636681470078E+14) ["source"]=> string(94) "http://sphotos-c.ak.fbcdn.net/hphotos-ak-ash3/s720x720/547023_463668147007798_1259271309_n.jpg" ["offset_y"]=> int(0) } }
As you can see it begins with object(stdClass) instead it should be an array, so adding the code get_object_vars() will return an array format not an stdClass, as you can see from this var_dump:
array(20) { ["about"]=> string(60) "Red Dragon Tattoo & Piercing is devoted to inking Cincinnati" ["checkins"]=> int(144) ["description"]=> string(509) "Red Dragon has been open since Feb. 2009, After Gabriel started constructing J began to Fill the chairs with his large following, after only a few months we brought on Chuck and Jocelyn to help with the overwhelming amount of people ready to get tattooed in the Colerain area and we've been inking up Cincinnati since then. We appreciate artfull expressions, and can help you make your own statement to this world through your body. If it's a body piercing, or a tattoo, what better way to express yourself." ["general_info"]=> string(59) "Artists: J, Chuck Hagedorn, Jocelyn Taylor, Gabriel Lowe " ["hours"]=> object(stdClass)#2 (12) { ["mon_1_open"]=> string(5) "13:00" ["mon_1_close"]=> string(5) "20:00" ["tue_1_open"]=> string(5) "13:00" ["tue_1_close"]=> string(5) "20:00" ["wed_1_open"]=> string(5) "13:00" ["wed_1_close"]=> string(5) "20:00" ["thu_1_open"]=> string(5) "13:00" ["thu_1_close"]=> string(5) "20:00" ["fri_1_open"]=> string(5) "13:00" ["fri_1_close"]=> string(5) "20:00" ["sat_1_open"]=> string(5) "13:00" ["sat_1_close"]=> string(5) "20:00" } ["is_published"]=> bool(true) ["location"]=> object(stdClass)#3 (7) { ["street"]=> string(17) "9242 Colerain Ave" ["city"]=> string(10) "Cincinnati" ["state"]=> string(2) "OH" ["country"]=> string(13) "United States" ["zip"]=> string(10) "45251-2406" ["latitude"]=> float(39.239511218398) ["longitude"]=> float(-84.592958873707) } ["parking"]=> object(stdClass)#4 (3) { ["street"]=> int(0) ["lot"]=> int(1) ["valet"]=> int(0) } ["phone"]=> string(17) "+1 (513) 385-6500" ["price_range"]=> string(10) "$$$$ (50+)" ["talking_about_count"]=> int(97) ["username"]=> string(19) "RDTATTOOANDPIERCING" ["website"]=> string(20) "rdtattoopiercing.com" ["were_here_count"]=> int(535) ["category"]=> string(14) "Local business" ["id"]=> string(15) "151284611579488" ["name"]=> string(28) "Red Dragon Tattoo & Piercing" ["link"]=> string(43) "http://www.facebook.com/RDTATTOOANDPIERCING" ["likes"]=> int(835) ["cover"]=> object(stdClass)#5 (3) { ["cover_id"]=> float(4.636681470078E+14) ["source"]=> string(94) "http://sphotos-c.ak.fbcdn.net/hphotos-ak-ash3/s720x720/547023_463668147007798_1259271309_n.jpg" ["offset_y"]=> int(0) } }