[英]Error message on simplexml_load_file()
我是PHP函数的新手,试图在终端中使用simplexml_load_file()读取xml文件,但出现如下代码所示的错误。 我不知道这是否有所不同,但我在Mac OS X OS上运行,Mountain Lion和xml文件位于本地框上的目录中。 任何建议/方向将不胜感激。 问候。
这是函数:
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);
}
}
}
我收到的错误如下在我的终端中:
PHP警告:simplexml_load_file():I / O警告:无法在第47行的/Users/msavoy/Sites/TestScripts/xmlFileLoader.php中加载外部实体“ sfly-6x8.000020513524-7001536_28935-tb.33.xml”
警告:simplexml_load_file():I / O警告:无法在第47行的/Users/msavoy/Sites/TestScripts/xmlFileLoader.php中加载外部实体“ sfly-6x8.000020513524-7001536_28935-tb.33.xml”
当我在$ xmlFile上执行var_dump时,我得到正确的文件名:sfly-6x8.000020513524-7001536_28935-tb.33.xml
所以我不确定是什么问题。 再次感谢!
问题是我需要在simplexml_load_file($ xmlFile)方法中定义FULL PATH。 我只需要继续寻找。
抱歉。
不管怎么说,还是要谢谢你。
编辑您的php.ini文件,可能已禁用此方法。 请记住,simplexml_load_file()仅在PHP 5中有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.