Skip to content
Advertisement

How to add values from an XML file to a csv file in php?

I have a link to an online XML file that contains different values. I have written a code that allows me to retrieve the contents of two specific tags in this file and put them in a csv file.

The first tag is the :

JavaScript

And the second one is a url with :

JavaScript

My problem is that in the output csv file I do get the urls but they are put in columns and the id does not get put in my csv file :

enter image description here

How can I do please to have the output file like this?

enter image description here

JavaScript

Advertisement

Answer

you could use SimpleXML to parse the XML and find data, instead of trying to search in XML string.

Note that fputcvs() takes an array as second argument.

JavaScript

Will generate a CSV file like this :

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