.xml to .php ?

Discussion in 'PHP' started by n00bl3t, Apr 13, 2012.

  1. #1
    Hello,

    I have this code:

    
    <?php
    $sitemap = "http://www.mysitehere/sitemap.xml"; // change the location if needed
    $xmlDoc = new DOMDocument();
    $xmlDoc->load($sitemap);
    $x = $xmlDoc->getElementsByTagName("url");
    $size=0;
    foreach ($x AS $item){ $size++; }
    $xmlDoc->load($sitemap);
    $y = $xmlDoc->getElementsByTagName("url");
    $string = "Location: ";
    $randomURL = rand(1, $size);
    $i=1;
    foreach ($y As $p)
    {
        if($i==$randomURL)
        {
            $toOpen = $p->getElementsByTagName("loc");
            $toOpenURL = $toOpen->item(0)->nodeValue;
            $string = $string.$toOpenURL;
            header($string);
        }
        $i++;
    }
    ?>
    
    PHP:
    How do I make the $sitemap read rss.php ?

    This is a very old code I used... and I remember that the code above can actually work on http://www.mysitehere/rss.php

    so it redirects all users into the URL inside the /rss.php
     
    n00bl3t, Apr 13, 2012 IP
  2. n00bl3t

    n00bl3t Well-Known Member

    Messages:
    383
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Anybody? There should be someone who knows how to change the variable here?
     
    n00bl3t, Apr 13, 2012 IP
  3. n00bl3t

    n00bl3t Well-Known Member

    Messages:
    383
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    120
    #3
    I will send $20 to your paypal email if you can send me a working code....
     
    n00bl3t, Apr 13, 2012 IP
  4. Arttu

    Arttu Member

    Messages:
    139
    Likes Received:
    2
    Best Answers:
    8
    Trophy Points:
    40
    #4
    Can you pm me the link to your rss.php or give me an example of the output of your rss.php.
     
    Arttu, Apr 14, 2012 IP
  5. Tawfik64

    Tawfik64 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Here is a another code for reading rss using SimpleXml . I hope it will help you ,there is no need for the 20$ :)
     <?php
    $RSS_content = file_get_contents('http://www.mysitehere/rss.php'); 
    $Xml = new SimpleXmlElement($RSS_content); 
    $size=0;
    foreach($Xml ->channel->item as $entry){ $size++; }
    $string = "Location: ";
    $randomURL = rand(1, $size);
    $i=1;
    foreach ($Xml ->channel->item as $entry)
    {
       if($i==$randomURL)
       {
         $string = $string.$entry->link;
         header($string);
       }
       $i++;
    }
    ?>
    PHP:
     
    Tawfik64, Apr 16, 2012 IP
  6. vineld

    vineld Greenhorn

    Messages:
    53
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    18
    #6
    file_get_contents will not work if allow_url_fopen is off. This is the case with quite a few web hosting companies for security reasons. If it doesn't work you can use curl instead.
     
    vineld, Apr 17, 2012 IP