Reputation: 1531
I am new to PHP functions and trying to use the simplexml_load_file() to read an xml file in my terminal but getting an error as stated below my code. I don't know if this makes a difference or not but I'm running on the mac os x OS, Mountain Lion and the xml file is sitting in a directory on my local box. Any suggestions/direction would be greatly appreciated. Regards.
Here is the function:
function xmlFileLoader($sourceDir) {
// Properties
$sourceXmlDir = scandir($sourceDir);
$count_xml_files = count($sourceXmlDir);
// Removes any directory or file other than XML file from the contents of the $sourceDir variable:
for( $i = 0; $i < $count_xml_files; $i++ ) {
$path_info = pathinfo( $sourceXmlDir[$i] );
if( preg_match( '/^\./', $sourceXmlDir[$i] ) || is_dir( $sourceXmlDir . '/' . $sourceXmlDir[$i] ) || ( strtoupper( $path_info['extension'] ) <> 'XML' ) )
{
unset( $sourceXmlDir[$i] );
}
}
// Get the correct count of the values in the $sourceXmlDir after the unset function completes
$sourceXmlArray = array_values($sourceXmlDir);
$count_xml_files = count($sourceXmlArray);
if ($count_xml_files > 0) {
// Cycle through the XML files in the $sourceXmlArray
foreach ($sourceXmlArray as $xmlFile) {
$sFile = simplexml_load_file($xmlFile);
print_r($sFile);
}
}
}
The error that I'm getting is as follows in my terminal:
PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "sfly-6x8.000020513524-7001536_28935-tb.33.xml" in /Users/msavoy/Sites/TestScripts/xmlFileLoader.php on line 47
Warning: simplexml_load_file(): I/O warning : failed to load external entity "sfly-6x8.000020513524-7001536_28935-tb.33.xml" in /Users/msavoy/Sites/TestScripts/xmlFileLoader.php on line 47
When I do a var_dump on the $xmlFile I get the correct file name: sfly-6x8.000020513524-7001536_28935-tb.33.xml
So I'm not sure what the problem is. Thanks again!
Upvotes: 0
Views: 751
Reputation: 1531
The issue was that I needed to define the FULL PATH in the simplexml_load_file($xmlFile) method. I just had to keep on looking.
Sorry.
Thanks anyway.
Upvotes: 1
Reputation: 2374
Edit your php.ini file, probably this method be deactivated. Remember simplexml_load_file() just work in PHP 5.
Upvotes: 0