0

This is what I currently have for my PHP file:

<?php header("Content-type: text/xml"); ?>
<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; ?>
<rss version="2.0">
<channel>
  <title>My Website</title>
  <link>http://www.mywebsite.com</link>
  <description>The Title of My Website</description>
  <pubDate>Tue, 15 Apr 2008 18:00:00 +0000</pubDate>

  <item>
    <title>Website Directory - Page NUMBER</title>
    <pubDate><?echo date('Y/m/d H:i:s');?></pubDate>
    <link>http://www.mywebsite.com/directory/NUMBER</link>
    <description>New update to page NUMBER in the Website Directory.</description>
  </item>

</channel>
</rss>

That right there is correctly showing one entry in the RSS feed. However, I need it to show 30 entries, each with a random number entered in the three places where NUMBER is shown in the item.

Each RSS item should have a different number between 1 and 2779503 entered in the three places that say NUMBER. I know that PHP has http://php.net/manual/en/function.rand.php but what I don't know how to do is have it loop through 30 random numbers each time the feed is loaded...

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
user1848777
  • 551
  • 1
  • 4
  • 9
  • My 'stupid' answer would be to simply replace NUMBER with `= mt_rand(1, 2779503) ?>`, but I have a feeling that's not actually what you want.. It would probably be helpful if you state what you are hoping to achieve with this.. – Evert Nov 25 '12 at 01:53
  • If I just enter `= mt_rand(1, 2779503) ?>` in each of those three places that same NUMBER each item in the RSS has different numbers. For example, the same item would be showing 3 different numbers. What I want it for each item to show the same NUMBER in those three places and for there to be 30 unique items. – user1848777 Nov 25 '12 at 01:56

1 Answers1

1
<?php
    foreach( range( 1, 30 ) as $i ):
        $number = mt_rand( 1, 2779503 );
?>
<item>
    <title>Website Directory - Page <?php echo $number; ?></title>
    <pubDate><?echo date('Y/m/d H:i:s');?></pubDate>
    <link>http://www.mywebsite.com/directory/<?php echo $number; ?></link>
    <description>New update to page <?php echo $number; ?> in the Website Directory.</description>
</item>
<?php endforeach; ?>
soulseekah
  • 8,770
  • 3
  • 53
  • 58