php - xml - 随机过滤并存储订单 [英] php - xml - random filter and store the order

查看:21
本文介绍了php - xml - 随机过滤并存储订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP:我得到了 20 篇文章的 XML 提要,我随机挑选了 3 篇文章并以相同的格式打印了 xml.随机选择的文章应该每天随机更改,而不是每次刷新.

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.

例如:art1、art2、art3、art......art20它应该显示:art4、art2、art 19(随机)但它应该整天都在同一篇文章 -(10/12/12)明天它应该是 art1、art20、art13(另一个随机集)

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);}

谢谢

推荐答案

如何使用日期名称保存您的文件,然后检查该日期不存在

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' );

 // Write our updated XML back to a new file
            if( date( "Y/m/d", filemtime( 'feedout.xml' ) ) != $date )
                $doc->save( 'feedout.xml' );

这篇关于php - xml - 随机过滤并存储订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆