小编cel*_*ian的帖子

PHP:如何遍历目录中的每个XML文件?

我正在构建一个简单的应用程序.它是在线订购系统的用户界面.

基本上,系统将这样工作:

  1. 其他公司将其采购订单上传到我们的FTP服务器.这些订单是简单的XML文件(包含客户数据,地址信息,订购产品和数量......)

  2. 我在HTML5,jQuery和CSS中构建了一个简单的用户界面 - 全部由PHP提供支持.

  3. PHP读取订单的内容(使用SimpleXML的内置功能)并将其显示在网页上.

所以,它是一个Web应用程序,应该始终在办公室的浏览器中运行.PHP应用程序将显示所有订单的内容.每十五分钟左右,该应用程序将检查新订单.

如何遍历目录中的所有XML文件?

现在,我的应用程序能够读取单个XML文件的内容,并在页面上以一种很好的方式显示它.

我当前的代码如下所示:

// pick a random order that I know exists in the Order directory:
$xml_file = file_get_contents("Order/6366246.xml",FILE_TEXT);
$xml = new SimpleXMLElement($xml_file);

// start echo basic order information, like order number:
echo $xml->OrderHead->ShopPO;
// more information about the order and the customer goes here…

echo "<ul>";

// loop through each order line, and echo all quantities and products:
foreach ($xml->OrderLines->OrderLine as $orderline) {
    "<li>".$orderline->Quantity." st.</li>\n".
    "<li>".$orderline->SKU."</li>\n";
}
echo "</ul>";

// more …
Run Code Online (Sandbox Code Playgroud)

php xml directory loops simplexml

3
推荐指数
1
解决办法
9861
查看次数

标签 统计

directory ×1

loops ×1

php ×1

simplexml ×1

xml ×1