Converting Comma Delimited File to XML

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
azpaul
Forum Newbie
Posts: 2
Joined: Sun Dec 19, 2004 9:52 pm
Location: Chandler Arizona

Converting Comma Delimited File to XML

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

http://uk.php.net/xml

is your best starting point.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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. :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

*cough* fgetcsv() *cough*

:)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Yeah, that works great, too. :)
Post Reply