Reputation: 287
PHP: I get XML feed of 20 articles, I have pick 3 articles randomly and print xml out in the same format. Randomly picked article should change random every day not on every refresh.
so for ex: art1, art2, art3,art......art20 it should display: art4, art2, art 19 (random) but it should with the same article for the entire day - (10/12/12) and tomorrow it should be art1,art20,art13 (another random set)
<?php
// Load our XML document
$doc = new DOMDocument();
$doc->load('feed.xml');
// Create an XPath object and register our namespaces so we can
// find the nodes that we want
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('p', 'http://purl.org/dc/elements/1.1/');
// Random generated xml should go here
// Write our updated XML back to a new file
$doc->save('feedout.xml');
?>
Since storing the article order needs server file storage, I can push that back. How can I randomize the article
for ($i = 0; $i < $nodes->3; $i++) {
$node = $nodes->item($i);}
Thanks
Upvotes: 2
Views: 187
Reputation: 5271
How about just save your file with a date name and then check that date doesn't already exist
// Write our updated XML back to a new file
if( !file_exists( $date . '_feedout.xml' ) )
$doc->save( $date . '_feedout.xml' );
Or
// Write our updated XML back to a new file
if( date( "Y/m/d", filemtime( 'feedout.xml' ) ) != $date )
$doc->save( 'feedout.xml' );
Upvotes: 1