我正在測試一些使用PHP讀取XML的東西。下面是XML文件的示例:用PHP讀取XML
<?xml version="1.0" encoding="UTF-8" ?>
<BroadcastData creationDate="20140326085217">
<ScheduleData>
<ChannelPeriod beginTime="20140326090000" endTime="20140402044500">
<ChannelId>Rai Uno</ChannelId>
<Event beginTime="20140326090000" duration="1800">
<EventId>260852180006</EventId>
<EventType>P</EventType>
<EpgProduction>
<EpgText language="eng">
<Name>Unomattina storie vere</Name>
</EpgText>
</EpgProduction>
</Event>
<Event beginTime="20140326093000" duration="1500">
<EventId>260852180007</EventId>
<EventType>P</EventType>
<EpgProduction>
<EpgText language="eng">
<Name>Unomattina Verde</Name>
</EpgText>
</EpgProduction>
</Event>
這是我創建的PHP腳本,但是當我運行PHP文件時沒有顯示任何內容。
<?php
$completeurl ="test.xml";
$xml = simplexml_load_file($completeurl);
$info = $xml->BroadcastData->ScheduleData->ChannelPeriod->ChannelId;
for ($i = 0; $i++) {
$begintime = $info[$i]->Event->attributes()->beginTime;
echo "<p>Channel: ".$info."<br/>"."Begin Time: ".$begintime."</p>";
}
?>
非常感謝您的幫助!
'爲( $ i = 0; $ i> 0; $ i ++){'...你認爲這個循環會啓動嗎? :) –
嗨@傑克,我已經登陸了這樣的循環,但它仍然不工作:'for($ i = 0; $ i ++){ $ begintime = $ info [$ i] - > Event- >屬性() - > BEGINTIME; echo「
Channel:」。$ info。「
」; }' – RCB」。「Begin Time:」。$ begintime。「