Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6589813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:13:21+00:00 2026-05-25T17:13:21+00:00

I am using PHP to grab an XML feed and display it in my

  • 0

I am using PHP to grab an XML feed and display it in my website, the feed is coming from
This NewsReach Blog.

I am using some simple PHP code to get the details as show below:

    $feed = new SimpleXMLElement('http://blog.newsreach.co.uk/atom.xml', null, true);

    $i = 0;

    foreach($feed->entry as $entry)
    {
        if ($i < 4)
        {
            $title = mysql_real_escape_string("{$entry->title}");
            $summary = mysql_real_escape_string("{$entry->content}");
            $summary = strip_tags($summary);
            $summary = preg_replace('/\s+?(\S+)?$/', '', substr($summary, 0, 100));
            $url = mysql_real_escape_string("{$entry->link[4]['href']}");
            $media = $entry->children('http://search.yahoo.com/mrss/');
            $attrs = $media->thumbnail[0]->attributes();
            $img = $attrs['url'];
        }
    }

The problem that I have is that the media thumbnail tag does not exist in every blog post which causes an error to appear and stop the XML Grabber from functioning.

I have tired things like:

    if ($media == 0)
    {
    }
    else
    {
        $attrs = $media->thumbnail[0]->attributes();
            $img = $attrs['url'];
    }

or

    if ($media['thumbnail'] == 0)
    {
    }
    else
    {
        $attrs = $media->thumbnail[0]->attributes();
            $img = $attrs['url'];
    }

which I had no luck with, I was hoping someone could help me check if the XML Item existed and then process depending on that.

Thanks all

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:13:22+00:00Added an answer on May 25, 2026 at 5:13 pm

    You could check if it’s set and not empty:

    $img = '';
    if (!empty($media->thumbnail[0])) {
        $attrs = $media->thumbnail[0]->attributes();
        $img = $attrs['url'];
    }
    

    Remember that $media is an object, you can’t access it like an array ($media['thumbnail'] should be $media->thumbnail).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using php xpath to get the values from the below xml feed
Using php coding, I'm attempting to make a script which will grab content from
I am using this PHP function to grab all <img> tags within any given
I want to grab data from a mysql database by using php. The data
I'm using a very simple PHP include to grab my current twitter status and
I am using php and mysql to grab and display details depending on the
Using PHP, what's the fastest way to convert a string like this: 123 to
Using PHP ... This is for my personal use so I'm thinking maybe 3-4
I'm using the Zend Framework, specifically the Zend_Feed class, to grab the Facebook XML
I'm trying to parse this feed: http://musicbrainz.org/ws/1/artist/c0b2500e-0cef-4130-869d-732b23ed9df5?type=xml&inc=url-rels I want to grab the URLs inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.