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 732367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:08:01+00:00 2026-05-14T07:08:01+00:00

I have the following XML array: [link]=> array(2) { [0]=> object(SimpleXMLElement)#311 (1) { [@attributes]=>

  • 0

I have the following XML array:

["link"]=>
          array(2) {
            [0]=>
            object(SimpleXMLElement)#311 (1) {
              ["@attributes"]=>
              array(3) {
                ["type"]=>
                string(9) "text/html"
                ["href"]=>
                string(48) "http://twitter.com/bob/statuses/1226112723"
                ["rel"]=>
                string(9) "alternate"
              }
            }
            [1]=>
            object(SimpleXMLElement)#312 (1) {
              ["@attributes"]=>
              array(3) {
                ["type"]=>
                string(9) "image/png"
                ["href"]=>
                string(59) "http://a3.twimg.com/profile_images/226895523/Dan_normal.png"
                ["rel"]=>
                string(5) "image"
              }
            }
          }

It’s inside a bigger array, I need to get the first and second hef attribute seperatly so that I can put one href as a <a> link and another with a <img>.

How can I output each href rather than both together?

Currently trying this:

 foreach($entry->link as $link) {
     echo $link->attributes()->href;
 }
  • 1 1 Answer
  • 1 View
  • 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-14T07:08:01+00:00Added an answer on May 14, 2026 at 7:08 am
    $url = 'http://api.twitter.com/1/favorites/bob.atom';
    $feed = simplexml_load_file($url);
    
    $testStop = 0;
    foreach($feed->entry as $entry) {
      echo 'title: ', $entry->title, "\n";
    
      // store all link/@href in a hashtable
      // so you can access them in any order you like
      // without resorting to xpath or alike.
      $links = array();
      foreach($entry->link as $link) {
        $links[(string)$link['rel']] = (string)$link['href'];
      }
    
      if ( isset($links['image']) ) {
        echo '<img src="', $links['image'], '" />', "\n";
      }
      if ( isset($links['alternate']) ) {
        echo '<a href="', $links['alternate'], '" />alternate</a>', "\n";
      }
      echo "----\n";
      if ( 2 < ++$testStop ) die;
    }
    

    (currently) prints

    title: kolchak: Sometimes I think I need a new butler. But then it's like "Nah, he's still got one thumb. We good."
    <img src="http://a1.twimg.com/profile_images/668496250/Picture_14_normal.jpg" />
    <a href="http://twitter.com/kolchak/statuses/10648055680" />alternate</a>
    ----
    title: shitmydadsays: "War hero? No. I was a doc in Vietnam. My job was to say "This is what happens when ."
    <img src="http://a3.twimg.com/profile_images/362705903/dad_normal.jpg" />
    <a href="http://twitter.com/shitmydadsays/statuses/10580558323" />alternate</a>
    ----
    title: shitmydadsays: "I lost 20 pounds...How? I drank bear piss and took up fencing. How the you think, son? I exercised."
    <img src="http://a3.twimg.com/profile_images/362705903/dad_normal.jpg" />
    <a href="http://twitter.com/shitmydadsays/statuses/10084782056" />alternate</a>
    ----
    

    But you might also be interested in xsl(t)

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

Sidebar

Related Questions

I have the following simple xml object file: [AuthorList] => SimpleXMLElement Object ( [@attributes]
I have the following xml: <objects> <property name=steps> <property name=array> <object type=com.tn.assistant.models.Step> <property name=preDialogues>
Hi I have following simple xml object: [ad] => Array ( [0] => SimpleXMLElement
I have the following item in preferences.xml : <ListPreference android:key=pref_movies_min_imdb android:title=@string/pref_movies_min_imdb android:summary=@string/pref_movies_min_imdb_summary android:entries=@array/pref_movies_min_imdb_array_entries android:entryValues=@array/pref_movies_min_imdb_array_values
I have the following XML Document: <?xml version=\1.0\ encoding=\UTF-8\?> <atom:entry xmlns:atom=\http://www.w3.org/2005/Atom\ xmlns:apps=\http://schemas.google.com/apps/2006\ xmlns:gd=\http://schemas.google.com/g/2005\> <apps:property
I have the following XML: http://pastebin.com/QiRK72BK which is generated in response to a REST
I have the following XML <plist version=1.0> <dict> <key>items</key> <array> <dict> <key>assets</key> <array> <dict>
I have the following xml code in my xml: <features> <pool type=inground>yes</pool> <heating type=other/>
Say we have the following XML: <people> <person> <name>Jake</name> <skills> <skill>JavaScript</skill> <skill>HTML</skill> <skill>Flex</skill> <skill>CSS</skill>
I have the following XML: <?xml version=1.0 encoding=UTF-8?> <gnm:Workbook xmlns:gnm=http://www.gnumeric.org/v10.dtd xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.gnumeric.org/v9.xsd> <office:document-meta xmlns:office=urn:oasis:names:tc:opendocument:xmlns:office:1.0

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.