0
function getNews()
{
    $bloggerDataStr = file_get_contents("http://www.blogger.com/feeds/3018390933290471377/posts/default/-/comp?alt=json");
    $bloggerDataArr = json_decode($bloggerDataStr);

    $html .= '<ul>';

    foreach($bloggerDataArr->feed->entry as $entry)
    {
        $html .= '<li>';
        $html .= '<h1>'.$entry->title->$t.'</h1>';
        $html .= '<time>'.$entry->published->$t.'</time>';

        $html .= '<section>'.$entry->content->$t.'</section>';

        $html .= '</li>';
    }

    $html .= '</ul>';

    return $html;
}

I get "Fatal error: Cannot access empty property" in:

$entry->title->$t.

I believe my code is correct, I don't understand what is wrong. Help? Thanks

0

3 Answers 3

3

$t is a variable name in PHP. Try $entry->title->{'$t'}.

Sign up to request clarification or add additional context in comments.

1 Comment

My bad! I missed the single quotes around $t. :p +1 cos I'm an idiot. :)
0

Try with a var_dump to check for the properties you are looking for

1 Comment

This is actually not all that helpful, since the property is "$t".
0

Probably this isn't the most elegant solution possible, but it works for me: Since the problem is the dollar sign in the name of the parameter, Try to substitute "$entry->title->$t" with $entry->title->{chr(36) . 't'}

Here's your edited code:

$bloggerDataStr = file_get_contents("http://www.blogger.com/feeds/3018390933290471377/posts/default/-/comp?alt=json");
$bloggerDataArr = json_decode($bloggerDataStr);

$html .= '<ul>';

foreach($bloggerDataArr->feed->entry as $entry)
{
    $html .= '<li>';
    $html .= '<h1>'.$entry->title->{chr(36) . 't'}.'</h1>';
    $html .= '<time>'.$entry->published->{chr(36) . 't'}.'</time>';

    $html .= '<section>'.$entry->content->{chr(36) . 't'}.'</section>';

    $html .= '</li>';
}

$html .= '</ul>';

return $html;

2 Comments

Using chr() is completely unnecessary so long as you use single quotes to inhibit variable substitution.
Yeah, that's true I added them because I'm used to put double quotes everywhere on my code, and I believed that using single or double quote would be the same (except having to push two keys on the keyboard instead of one). Infact before posting the code I have changed all the double quotes into single quotes :-)

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.