When I use simplexml_load_file to individual file, it works fine. However, since I have so many of them, when I tried to run my script to a batch of files.
In case this is relavant, I have two kind of log files to load into my database. One starts with . The other starts with . (But looking at the error, the error occurs even w/ the same structure.)
<?php
$dir_path = ".";
if ($dir_handler = opendir($dir_path)) {
while (($sub_dir = readdir($dir_handler)) !== false) { //reading all sub dir
if (is_dir($sub_dir)) {
if (substr($sub_dir,0,6) == "201209") { //filter only desired sub dir
$sub_dir_handler = opendir($sub_dir);
while($file = readdir($sub_dir_handler)) { //reading files in each
//qualified sub dir
if (($file != ".") && ($file != "..")) { //except . and ..
$xml = simplexml_load_file($file); // got error on
//the second file
if ($xml->getname() != "hash") { // tried to distinct
// structure type but error
I guess simplexml_load_file return false (error)
You can see those using libxml_get_errors, cf http://php.net/manual/en/simplexml.examples-errors.php
Edit:
Considering your 2nd comment, looks like your file is not accessible to SimpleXML…