0

私は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 警告: 外部エンティティ "sfly-6x8.000020513524-7001536_28935-tb.33.xml" の /Users/msavoy/Sites/TestScripts/xmlFileLoader.php 行 47 の読み込みに失敗しました

警告: simplexml_load_file(): I/O 警告: 外部エンティティ "sfly-6x8.000020513524-7001536_28935-tb.33.xml" の /Users/msavoy/Sites/TestScripts/xmlFileLoader.php 行 47 の読み込みに失敗しました

$xmlFile で var_dump を実行すると、正しいファイル名が得られます: sfly-6x8.000020513524-7001536_28935-tb.33.xml

だから私は問題が何であるか分かりません。再度、感謝します!

4

2 に答える 2

1

問題は、simplexml_load_file($xmlFile) メソッドで FULL PATH を定義する必要があることでした。見続けるしかなかった。

ごめん。

とにかくありがとう。

于 2012-09-28T19:57:57.987 に答える
0

php.ini ファイルを編集します。おそらくこのメソッドは無効になっています。simplexml_load_file() は PHP 5 で動作することを思い出してください。

于 2012-09-28T19:33:11.430 に答える