Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an rss in xml form with who contain (well formatted)

$xml = simplexml_load_file("/rss.xml");
echo $xml->item[0]->guid;

This code give me nothing. If I var_dump the $xml, I get 40 array.

Can someone guess why?

edit:

Well... is a NSFW commision so care.. RSS file -> http://www.xvideos.com/rss/rss.xml (view-source:http://www.xvideos.com/rss/rss.xml for chrome)

var_dump:

object(SimpleXMLElement)#1 (2) {
  ["@attributes"]=>
  array(1) {
    ["version"]=>
    string(3) "2.0"
  }
  ["channel"]=>
  object(SimpleXMLElement)#2 (6) {
    ["title"]=>
    string(11) "Xvideos.com"
    ["link"]=>
    string(23) "http://www.xvideos.com/"
    ["description"]=>
    string(43) "Xvideos, free hosting for free porn videos."
    ["lastBuildDate"]=>
    string(31) "Mon, 18 Nov 2013 05:03:00 +0100"
    ["ttl"]=>
    string(2) "20"
    ["item"]=>
    array(40) {
      [0]=>
      object(SimpleXMLElement)#3 (5) {
        ["title"]=>
        string(23) "..."
        ["description"]=>
        string(766) ".. "
        ["link"]=>
        string(59) "http://www.xvideos.com/..."
        ["guid"]=>
        string(12) "video5748963"
        ["pubDate"]=>
        object(SimpleXMLElement)#43 (0) {
        }
      }
      [1]=>
      object(SimpleXMLElement)#4 (5) {
        ["title"]=>
        string(48) "...s"
        ["description"]=>
        string(789) "..."
        ["link"]=>
        string(84) "http://www.xvideos.com/,,,"
        ["guid"]=>
        string(12) "video4863479"
        ["pubDate"]=>
        object(SimpleXMLElement)#43 (0) {
        }
      }
 ....
share|improve this question
4  
show your dump. And your XML –  Cfreak Nov 18 at 16:28
 
uh that doesn't sound right :s –  thelolcat Nov 18 at 16:30
 
edited with infos, mostly NSFW so care. –  ItalianOne Nov 18 at 16:35
1  
you should remove the porn links, is it an ad or a real question ? you are accessing the xml->item but items is in xml->channel->item, maybe the issue is here –  Koren Nov 18 at 16:41
 
As you can see in your var_dump, your item is not a direct child of $xml. echo $xml->channel->item[0]->guid;. –  Rocket Hazmat Nov 18 at 16:42
show 1 more comment

2 Answers

up vote 2 down vote accepted

It should be like

$xml->channel->item[1]->guid

that gets you the guid.

share|improve this answer
add comment

This is the structure of a typical RSS file:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        ...
        <item>...</item>
        <item>...</item>
        ...
    </channel>
</rss>

In your call, you have to omit the top level node (<rss> in this case) but not second level nodes:

echo $xml->item[0]->guid; // <channel>?
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.