Hkm Sadek
Hkm Sadek

Reputation: 3209

Getting data from php nested objects

I am trying to extract data from a php object that is actually retrived from the google blogger post feed. I tried using javascript and it works fine with dot notations. But I am not being able to do same with php.

Here is how the objects look like

stdClass Object
(
[id] => stdClass Object
    (
        [$t] => tag:blogger.com,1999:blog-8275521076679012362.post-3869147994923309099
    )

[published] => stdClass Object
    (
        [$t] => 2017-12-20T07:02:00.000-08:00
    )

[updated] => stdClass Object
    (
        [$t] => 2018-01-12T07:38:12.068-08:00
    )

[category] => Array
    (
        [0] => stdClass Object
            (
                [scheme] => http://www.blogger.com/atom/ns#
                [term] => stacks
            )

    )

[title] => stdClass Object
    (
        [type] => text
        [$t] => New #85 & 86: 2day Stack and LastPublished Stack
    )
 )

There are many but I am showing only few here.

Here is my code that I have tried.

for ($i=0; $i <$len ; $i++) { 
    $thisPost = $feedData->feed->entry[$i];
    print_r($thisPost); // The above object is printed because of this line.

}

The problem is, I am not being able to get the title or anything from the object.

Upvotes: 0

Views: 39

Answers (1)

Don&#39;t Panic
Don&#39;t Panic

Reputation: 41810

You're probably having trouble because of the $t property names.

If you try to access them with, for example, $thisPost->title->$t, it won't work because PHP will interpret the $t as a variable, which probably doesn't exist.

You can use complex syntax to specify that it's just a string.

$thisPost->title->{'$t'}

Upvotes: 1

Related Questions