Php 在包含simplexml的文件夹中读取多个xml文件
我应该读取文件夹中的许多xml文件并从这些数据中提取数据吗。 我没有问题阅读此代码的文件夹Php 在包含simplexml的文件夹中读取多个xml文件,php,xml,simplexml,opendir,Php,Xml,Simplexml,Opendir,我应该读取文件夹中的许多xml文件并从这些数据中提取数据吗。 我没有问题阅读此代码的文件夹 <?php $dir = "Dati/xml/nonletti/"; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if (($file !== '.') && ($file !== '..') ) { echo "
<?php
$dir = "Dati/xml/nonletti/";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (($file !== '.') && ($file !== '..') ) {
echo "$file \n";
}
}
closedir($dh);
}
}
?>
但是如果我尝试使用simplexml读取所有文件,我看不到任何东西
<?php
$dir = "Dati/xml/nonletti/";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (($file !== '.') && ($file !== '..') ) {
$xml = simplexml_load_file($file);
$RGSostituzione = $xml->attributes()->Sostituzione;
echo "<li>File $file - <b>Sostituzione:</b> $RGSostituzione</li>";
}
}
closedir($dh);
}
}
?>
attributes()->Sostituzione;
echo“文件$File-Sostituzione:$RGSostituzione ”;
}
}
closedir($dh);
}
}
?>
你能帮我告诉我怎么做吗?
谢谢-
Filippo当您读取目录中的文件时,您只会得到基本文件名,而不是完整路径。因此,在执行SimpleXML调用时,需要预先指定路径 改为:
$xml = simplexml_load_file($dir . $file);
(返回文件名,而不是整个文件路径)
(采用完整的文件路径)
$xml = simplexml_load_file($dir . $file);