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

  • SEARCH
  • Home
  • 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 6826755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:11:07+00:00 2026-05-26T22:11:07+00:00

I have the following data that I parsed from an xml file and now

  • 0

I have the following data that I parsed from an xml file and now I have a problem returning the data. How do i return the photo src data from the array within the photo array. Any ideas as to what I am doing wrong?

Code

$xml = simplexml_load_file($url);
$photo_url = $xml['photo']->src;

for ($i=0, $n=count($photo_url); $i<$n; ++$i) {
    echo $photo_url[$i].'<br>';
}

Data

["photo"]=>
  array(46) {
    [0]=>
    object(SimpleXMLElement)#2 (1) {
      ["@attributes"]=>
      array(6) {
        ["id"]=>
        string(5) "26001"
        ["src"]=>
        string(36) "1006416.jpg"
        ["thumb"]=>
        string(42) "1006416_thumb.jpg"
        ["title"]=>
        string(16) "album"
        ["subtitle"]=>
        string(6) "01.jpg"
        ["favorite"]=>
        string(0) ""
      }
    }
    [1]=>
    object(SimpleXMLElement)#3 (1) {
      ["@attributes"]=>
      array(6) {
        ["id"]=>
        string(5) "26001"
        ["src"]=>
        string(36) "1006417.jpg"
        ["thumb"]=>
        string(42) "1006417_thumb.jpg"
        ["title"]=>
        string(16) "album"
        ["subtitle"]=>
        string(6) "02.jpg"
        ["favorite"]=>
        string(0) ""
      }
    }
  • 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-26T22:11:08+00:00Added an answer on May 26, 2026 at 10:11 pm

    You should use the SimpleXMLElement attributes method, like so:

    $xml = simplexml_load_file($url);
    foreach( $xml as $xml_node)
    {
        $attributes = $xml_node->attributes();
        echo 'Photo source: ' . $attributes['src'] . "\n";
    }
    

    Demo

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

Sidebar

Related Questions

I have the following static method that prints the data imported from a 40.000
I have a data file that looks like the following example. I've added '%'
I have a program that is generating Xml Files from data out of a
I have built one 'deep' NSMutableDictionary that contains parsed XML data along with other
So I have the following data that represets the hour and quarter hour with
If I have the following data that is printed seperated by tabs using print
I have the following data set that I am trying to plot with ggplot2,
I have the following data model: I am writing a WCF service that needs
I have a column that has the following data: PersonId=315618 LetterId=43 MailingGroupId=1 EntityId=551723 trackedObjectId=9538
I have the following connection string: Data Source=localhost\\SQLEXPRESS; , it complains that '' is

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.