December 6th, 2013, 07:14 PM
How do I convert a csv file to xml in php?
I have a csv file which contains this data:
I want to create an xml file which looks like this:
December 6th, 2013, 07:20 PM
loop through that file use xmlwriter class to create an xml..
December 6th, 2013, 07:42 PM
What the heck is up with that CSV structure? It's totally messed up.
December 7th, 2013, 05:02 AM
oh my, i didnt obviously see the csv propelry, I thought it would be one line = related data..
that is not a nice way... and can cause problems
December 7th, 2013, 05:18 AM
Looks like it's supposed to be something like this:
Don't let Excel people mess with your data!
│ person1 │ person2 │ person3
first │ john │ steve │ mike
last │ doe │ whinney │ speirs
Fixing this will be ugly -- if your CSV is even valid. You'll first have to go through the whole CSV and put the data into a temporary array in order to untangle the structure. And then you have to go through the array to create your XML.
The correct format for the CSV would have been this:
If the "person1," "person2", ... stuff is important, you'd put it into an additional column.
Last edited by Jacques1; December 7th, 2013 at 05:23 AM.
December 7th, 2013, 07:31 AM
Unless there's a good reason for that structure, surely this would be more rational?
person, first, last
1, john, doe
2, steve, whinney
3, mike, speirs
Also much easier to convert to XML.
December 7th, 2013, 11:42 AM
Look at the post above yours.
December 7th, 2013, 11:46 AM
Originally Posted by Jacques1
Oops, and you even put them in code tags. I guess you win this round... haha