如何读取XML文件并从中读取值以显示在PHP编码的HTML页面中 [英] How to Read XML file and fetch values from it to display in PHP coded HTML page

查看:123
本文介绍了如何读取XML文件并从中读取值以显示在PHP编码的HTML页面中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML文件,其中有一些包含不同值的重复标签。我需要获取这些值并显示在我的网页中。请帮助我解决这个问题。

I Have a XML file which have some repetitive tags containing different values into it. I need to fetch those values and display in in my webpage. Please help me up in getting this.

推荐答案

非常简单,您可以这样做:

Quite simply, you could do something like this:

$raw = file_get_contents('path/to/xml/file.xml');

$blankarray = array();

$blank_xml = new SimpleXMLElement($raw);
foreach($blank_xml->channel->item as $item) {
$xml_item = array(
'content' => $description,
'date' => strtotime($item->pubDate),
'type' => 'Whateva'
);
array_push($blankarray, $xml_item);
}

foreach($blankarray as $item) {
echo '<li>' . $item["content"]
. '<a href="#">' . date(DATE_RFC822, $item["date"]) . '</a>'
. '</li>';
}

如果您有任何问题,请告知我。

Let me know if you have any questions.

这篇关于如何读取XML文件并从中读取值以显示在PHP编码的HTML页面中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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