Skip to content
Advertisement

Fatal error when trying to Parse a XML file to CSV in PHP

I am stuck on a bit of code for my program, where I am attempting to convert a XML document to CSV using a function in PHP. The code for the function is:

JavaScript

And I am calling it in the main script here:

JavaScript

the error message I get when running the script through XAMPP is:

JavaScript

Line 4 that it is referencing is the foreach statement in the createCSV function. I am really at a loss, and very new to PHP. I have had to teach myself PHP with mixed results, and any assistance would be highly appreciated.

Advertisement

Answer

You are considering $_FILES as the xml file, which is incorrect. $_FILES is an associative array of uploaded files. You need to open the file and read the data. To do so you can use simplexml_load_file:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement