Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何读取XML文件并从中提取值以显示在PHP编码的HTML页面中_Php_Html_Xml_File - Fatal编程技术网

如何读取XML文件并从中提取值以显示在PHP编码的HTML页面中

如何读取XML文件并从中提取值以显示在PHP编码的HTML页面中,php,html,xml,file,Php,Html,Xml,File,我有一个XML文件,其中有一些重复的标记,其中包含不同的值。我需要获取这些值并显示在我的网页中。请帮我弄清楚这一点。如果您使用的是PHP5,您可以查看SimpleXML。您可以在这里找到一个介绍教程:非常简单,您可以这样做: $raw = file_get_contents('path/to/xml/file.xml'); $blankarray = array(); $blank_xml = new SimpleXMLElement($raw); foreach($blank_xml-&g

我有一个XML文件,其中有一些重复的标记,其中包含不同的值。我需要获取这些值并显示在我的网页中。请帮我弄清楚这一点。

如果您使用的是PHP5,您可以查看SimpleXML。您可以在这里找到一个介绍教程:

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

$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>';
}
$raw=file\u get\u contents('path/to/xml/file.xml');
$blankarray=array();
$blank_xml=新的simplexmlement($raw);
foreach($blank_xml->channel->item as$item){
$xml\u item=array(
“内容”=>$description,
“日期”=>strottime($item->pubDate),
'类型'=>'什么'
);
数组\u推送($blankarray,$xml\u项);
}
foreach($blankarray作为$item){
回显“
  • ”.$item[“content”] . '' “
  • ”; }

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

    像这样一点吗?你的具体问题是什么?到目前为止你试过什么?什么不起作用?请发布您的代码。请不要链接到w3schools,有关原因,请参阅。