I have this code:

$xml = simplexml_load_file('http://****.ru/?format=feed&type=rss'); echo $xml->title;

And such a var_dump($xml) :

 object(SimpleXMLElement)#1 (2) { ["@attributes"]=> array(1) { ["version"]=> string(3) "2.0" } ["channel"]=> object(SimpleXMLElement)#2 (2) { ["image"]=> object(SimpleXMLElement)#3 (1) { ["url"]=> string(22) "http://*/img.jpg" } ["item"]=> array(20) { [0]=> object(SimpleXMLElement)#4 (6) { ["title"]=> string(12) "Smart Search" ["link"]=> string(48) "http://**/index.php/item/70-smart-search" ["description"]=> string(21) " ..." ["image_item"]=> string(98) "/var/www/user36565/data/www/*.ru/media/k2/items/cache/3749aaa8ee129d7e919bddcc7e09cd36_L.jpg" ["category"]=> string(15) "Utility Modules" ["pubDate"]=> string(31) "Tue, 17 Jan 2012 03:42:36 +0000" } [1]=> object(SimpleXMLElement)#5 (6) { ["title"]=> string(11) "Quick Icons" ["link"]=> string(47) "http://*.ru/index.php/item/69-quick-icons" ["descrip............. 

But in the end, the command echo $xml->title; shows just a white screen

Tell me what's wrong?

  • It is better to lay out the piece of xml that you want parsed. - VenZell
  • <? xml version = "1.0" encoding = "utf-8"?> <rss xmlns: yandex = " news.yandex.ru " xmlns: media = " search.yahoo.com/mrss " version = "2.0"> < channel> <image> <url> http: //*ru/img.jpg </ url> </ image> <item> <title> Smart Search </ title> <link> http: //*.ru/index .php / item / 70-smart-search </ link> <description> ... </ description> <image_item> / var / www / user36565 / data / www / *. com / media / k2 / items / cache / 3749aaa8ee129d7e919bddcc7e09cd36_L.jpg </ image_item> <category> Utility Modules </ category> <pubDate> Tue, 17 Jan 2012 03:42:36 +0000 </ pubDate> <yandex: full-text> </ yandex: full-text> </ item - Dmitriy333332
  • Found here that the problem is incomprehensible @attributes: hashcode.ru/questions/64464/… But I don’t understand how to do it - Dmitriy333332
  • Or not with him - Dmitriy333332
  • as well as $ xml-> channel-> title? - mountpoint

1 answer 1

http://ideone.com/4vMIx9
If there are many elements, then foreach will help to make a cycle on them and output