Aloha everyone,
I have another question. I have a SYDI script that retrieves WMI data from Windows computers, then appends a timestamp to the end of the file, and finally saves it to a share on a server. The PHP code I have to read and print out the filenames is shown below:
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file != "." && $file != "..") {
$results[] = $file;
echo $file . "<br />";
}
}
closedir($dh);
}
}
Everything is good and the filenames are returned as shown below:
sydiResult-24-Apr-11-18-59-52.xml
sydiResult-24-Apr-11-19-00-32.xml
sydiResult-24-Apr-11-19-01-17.xml
I’ve tried to use simplexml to call the files, in order, to see if I could even do it, with the following code:
for ($i = 0; $i < sizeof($results); $i++) {
$xml = simplexml_load_file($results[$i]);
}
but I get errors indicating that simplexml couldn’t open external xml files. The php file is in my htdocs directory, and the xml files are in a directory in the htdocs directory, called sydiResults. I wanted to separate the sydi xml files, so I decided to make the sub-directory. Could that be the reason simple xml won’t work?
My plan is simple: open an the xml files and extract certain information from it, then loop to the next xml file, extract certain information from it, then … so on and so on until I reach the last xml file in the directory. Does anyone have an idea of how I can use simplexml, or if I can use simplexml to open each xml file in turn?
Thanks in advance for any and all responses.
try this :