我想寫一個隨機生成xml文件的php。 PHP會生成一個介於1-10之間的隨機數字,每個數字1-10將在PHP中分配給它的xml文件,這將在生成相應數字時出現。使用rand()php函數來顯示隨機xml文件
到目前爲止,我有:
<?php
print rand() . "<br>";
print rand(1, 10);
?>
如何將XML文件集成到這個PHP?使用此XML例如:
例1
<?xml version="3.0" encoding="utf-8" ?>
<channel>
<title>The Dog in the Park</title>
<link>http://pets.com/doginthepark/</link>
<description>
The dog in the park
<item>
<guid>1234</guid>
<title>poodle's video</title>
例2
<?xml version="3.0" encoding="utf-8" ?>
<channel>
<title>The Cat in the Park</title>
<link>http://pets.com/kitteninthepark/</link>
<description>
The cat in the park
<item>
<guid>1235</guid>
<title>kitten video</title>
<item>
<guid>123455</guid>
<title>tiger video</title>
所以XML文件上面已分配的數字1 & 2.我將如何分配數量在代碼中正確的XML以及如何能夠生成數字1-10的隨機XML返回,這些數字還顯示XML文件的詳細信息。
任何幫助將不勝感激!很抱歉,如果這個問題是顯而易見的,我在這一個菜鳥:)
是XML的文件名爲'1.xml','2.xml' ......等等? – 2013-04-05 09:15:16
RE Marty McVry: XML文件分別被稱爲dogs.xml和cats.xml。 – therunningman 2013-04-05 09:22:52
RE馬克貝克: 您提到的問題討論生成XML文件保存到一個單獨的文件,而不是在PHP中。 – therunningman 2013-04-05 09:23:59