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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:55:14+00:00 2026-05-28T03:55:14+00:00

Recently I am using php to deal with a xml file. But I don’t

  • 0

Recently I am using php to deal with a xml file.

But I don’t know how to add a ‘break’ in my code.

The link is : http://babystory.diandian.com/rss

I want to use php to get the article named ‘[x]快乐王子’.But “foreach()” give me the last article named ‘[1]狼和七只小山羊’.

I want to add a break in “foreach()” so that I can get the article I want.

Here is my php code:

<?php
$xml = simplexml_load_file("http://babystory.diandian.com/rss");

foreach($xml->children() as $child){}

foreach($child->children() as $child2)

foreach($child2->children() as $child3)
{
  $element = $child3->getName();
  if($element=='title')
  {
    echo "<h1>" . $child3 . "</h1>";
  }

  if($element=='description')
  {
    echo $child3;
  }
}
?>

Could you help me to edit my code.Thank you very much.

  • 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-28T03:55:14+00:00Added an answer on May 28, 2026 at 3:55 am

    If you need to get the first item from your feed you don’t need any foreach loops at all.

    $xml = simplexml_load_file("http://babystory.diandian.com/rss");
    $item = (array)$xml->channel->item[0]; // the article [x]快乐王子 array
    

    Now $item is array of the first article information. So $item['title'] is [x]快乐王子, $item['link'] is http://babystory.diandian.com/post/2012-01-15/14770976, etc.

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

Sidebar

Related Questions

I was trying to solve this issue recently, but i don't really know how.
I am good in web development but recently started using PHP and developed few
This work great to delete php, txt and images but I recently starting using
I've recently learned how to join 2 arrays using the + operator in PHP.
I recently started using lcov to visualize my code coverage. It's a great tool.
I´ve recently started looking a web service calls using PHP. I can´t get the
I am using PHP 5.3 on Ubuntu 10.0.4. I recently upgraded from PHP 5.2
I have recently heard a lot of people argue about using PHP testing features
I recently started C++. I am using PHP right now and decided to take
I have been using php for a while but haven't taken the time to

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.