使用PHP

时间:2016-12-23 10:15:41

标签: php xml

我有像这样的数据pagenumber.xml数据

<?xml version="1.0" encoding="utf-8"?>
<Search>
<Pages Count="40">
<Page Number="1">Data in page1</Page>
<Page Number="2">Data in page2</Page>
<Page Number="3">Data in page3</Page>
<Page Number="4">Data in page4</Page>
<Page Number="5">Data in page5</Page>
</Pages>
</Search>

如何使用PHP在我的xml文件中显示数据 它是显示xml数据的代码,但在显示页面数据中仍然出错

<?php
$dataxml = simplexml_load_file('pagenumber.xml');

foreach($dataxml->Pages as $buku)
{
   echo "Pages count: ".$buku['Count']."<br>";
   echo "Data in page 1: --> i don't know how to show the data
   echo "Data in page 2: --> i don't know how to show the data
   echo "Data in page 3: --> i don't know how to show the data
   echo "Data in page 4: --> i don't know how to show the data
   echo "Data in page 5: --> i don't know how to show the data
}
?>

非常感谢;)

2 个答案:

答案 0 :(得分:0)

DataContext

答案 1 :(得分:0)

<?php
$dataxml = simplexml_load_file('pagenumber.xml');
foreach($dataxml->Pages as $buku)
{
   echo $buku->Page[0]; 
   echo $buku->Page[2]; 
   echo $buku->Page[3]; 
   echo $buku->Page[4]; 
   echo $buku->Page[5]; 
}
?>