PHP は初めてで、ローカル ボックスのフォルダーにある XML ファイルの出力を読み込もうとしています。PHP.net/simplexml_load_file チュートリアルでは、print_r($xml) を実行すると、次の LIKE コードで SimpleXMLElement オブジェクトが表示されるはずです。しかし、ローカル ターミナルでスクリプトを実行すると、ファイル パスが取得されます。
/Users/msavoy/XMLSourceDir/sfly-6x8.000020513524-7001536_28935-tb.33.xml
オブジェクト内のすべての要素を表示できるように、$xml オブジェクトを取得できる必要があります。
これが私のコードです:
// Get the correct count of the values in the $sourceXmlDir after the unset function completes
$sourceXmlArray = array_values($sourceXmlDir);
$count_xml_files = count($sourceXmlArray);
// Check to ensure that there are xml files in the directory before processing parsing the file
// If no files exist create an Exception and log the error.
if ($count_xml_files > 0) {
// Cycle through the XML files in the $sourceXmlArray
for ($i = 0; $i < $count_xml_files; $i++) {
$xml = ($sourceDir . '/' . $sourceXmlArray[$i]);
print_r($xml);
}
} else {
$error_output = date('Y-m-d H:i:s') . 'There are no XML files in the source directory: ' . $sourceDir;
error_log(date('Y-m-d H:i:s') . 'There are no XML files in the source directory: ' . $sourceDir);
throw new Exception($error_output);
}
私は何が欠けていますか?ヘルプ/指示をいただければ幸いです。よろしく。