fork download
  1. <?php
  2.  
  3. $xml = <<<'XML'
  4. <item>
  5. <title>title sdfs </title>
  6. <description>description text</description>
  7. <link>site.com/1</link>
  8. <item_news>
  9. <item_news_title>text 1</item_news_title>
  10. <item_news_description>description text 1</item_news_description>
  11. <item_news_url>google.ru</item_news_url>
  12. </item_news>
  13. <item_news>
  14. <item_news_title>text 2</item_news_title>
  15. <item_news_description>description text 2</item_news_description>
  16. <item_news_url>google.com</item_news_url>
  17. </item_news>
  18. </item>
  19. <item>
  20. <title>title sdfsdd </title>
  21. <description>description text 2</description>
  22. <link>site.ru/2</link>
  23. <item_news>
  24. <item_news_title>text 3</item_news_title>
  25. <item_news_description>description text 3</item_news_description>
  26. <item_news_url>google.de</item_news_url>
  27. </item_news>
  28. <item_news>
  29. <item_news_title>text 4</item_news_title>
  30. <item_news_description>description text 4</item_news_description>
  31. <item_news_url>google.fr</item_news_url>
  32. </item_news>
  33. </item>
  34. XML;
  35.  
  36. $data = new SimpleXMLElement('<data>' . $xml . '</data>');
  37. for($i = 0; $i < 2; ++$i) {
  38. $item = $data->item[$i];
  39. echo "<h3>". $item->title . "</h3>", PHP_EOL;
  40. echo $item->link."<br/>", PHP_EOL;
  41. echo $item->description."<br/>", PHP_EOL;
  42. foreach($item->item_news as $news) {
  43. echo $news->item_news_title, PHP_EOL;
  44. }
  45. echo '--------------------------', PHP_EOL;
  46. }
Success #stdin #stdout 0.02s 24392KB
stdin
Standard input is empty
stdout
<h3>title sdfs </h3>
site.com/1<br/>
description text<br/>
text 1
text 2
--------------------------
<h3>title sdfsdd </h3>
site.ru/2<br/>
description text 2<br/>
text 3
text 4
--------------------------