Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.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
在php中提供最新的xml文件_Php_Xml_Parsing_Sxml - Fatal编程技术网

在php中提供最新的xml文件

在php中提供最新的xml文件,php,xml,parsing,sxml,Php,Xml,Parsing,Sxml,也许有人可以帮助我,我提供了从PHPDB查询生成的xml文件,每个xml文件都有一个唯一的名称。现在我想准备一个函数,比如“获取最新的xml文件”,但我不知道最好的方法是什么 $xml = simplexml_load_file('test.xml'); 我找到了这个函数,但是我必须知道它的确切名称! 或者像这样的事情是可能的: $xml = simplexml_load_file('test.php'); 在test.php中,我有一个获取姓氏的函数,但是如何提供xml数据呢? 一些关键字

也许有人可以帮助我,我提供了从PHPDB查询生成的xml文件,每个xml文件都有一个唯一的名称。现在我想准备一个函数,比如“获取最新的xml文件”,但我不知道最好的方法是什么

$xml = simplexml_load_file('test.xml');
我找到了这个函数,但是我必须知道它的确切名称! 或者像这样的事情是可能的:

$xml = simplexml_load_file('test.php');
在test.php中,我有一个获取姓氏的函数,但是如何提供xml数据呢?
一些关键字如何我可以找到一个解决方案在谷歌将是非常有帮助的

该函数的第一个参数是文件名字符串。该文件应该是要加载的XML文件,因此不能使用其他php文件

因此,首先需要使用变量将文件名作为字符串获取。您应该能够在test.php文件中复制代码,然后保存文件名,而不是将其回显。然后在加载xml文件时使用该变量

e、 g


这是对我有效的最终解决方案

我用.htaccess保护目录,并在目录中存储所有生成的xml文件以及getLastXml.php文件

getLastXml.php

function get_last_file() {

    $lastFileTime = 0;
    foreach (glob("*.xml") as $filename) {
        if ($lastFileTime<filemtime($filename))
            {
                $lastFileTime = filemtime($filename);
                $lastFileName = $filename;
            }
        }

    return $lastFileName;
}

$lastXmlFile = get_last_file();
header ("Content-Type:text/xml");
echo file_get_contents($lastXmlFile);
在php文件中显示xml

echo file_get_contents($lastXmlFile);
加载xml文件的内容并显示它



加载xml数据看看,您肯定能够在PHP文件中显示xml!只需看看php中的set_头。谢谢,它帮助我找到了正确的方法!
 header ("Content-Type:text/xml");
echo file_get_contents($lastXmlFile);
simplexml_load_file("http://username:passwort@urlToTheDirectory/getLastXml.php");