Page 1 of 1

Converting Comma Delimited File to XML

Posted: Mon Dec 26, 2005 4:08 am
by azpaul
Hello,

I am looking to use PHP 4 to read a text file with multiple records in it and then write them to XML.

Can anyone point me in the right direction to do this task?

An example of five records would be very helpul.

Thanks.

Posted: Mon Dec 26, 2005 5:13 am
by Jenk
http://uk.php.net/xml

is your best starting point.

Posted: Mon Dec 26, 2005 5:28 am
by m3mn0n
Opening the file: file_get_contents()
Parsing the data: foreach(), explode()
Working with the data: you should have the elements in an array and from there, place them in whichever XML format you wish line by line via another foreach() loop
Writing the data: fwrite()

The examples and explainations on those pages are very good.

After giving that a try, if you have any issues feel free to revive this thread and ask. :)

Posted: Mon Dec 26, 2005 8:23 am
by feyd
*cough* fgetcsv() *cough*

:)

Posted: Mon Dec 26, 2005 8:30 am
by m3mn0n
Yeah, that works great, too. :)