Hi ,
I need the code to convert a csv file to XML file .
Kindly help me in this.
Regards,
Prithvi
feyd | Split from here.
CSV to XML
Moderator: General Moderators
should be something like this
should be something like this
something like this should work. be carefull will special characters like accents . xml will complain about them
Code: Select all
$lines = file('csv file here');
$xml='<DATASET>';
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
$line = str_replace(',',' ',$line); //remove any commas i thin you moight alse need to remove double quotes,maybe
$data = split(',',$line);
$xml .= '<DATAITEM>'
.'<FIELD1>' . $data[0] . '</FIELD1>'
.'<FIELD2>' . $data[1] . '</FIELD2>'
.'<FIELD3>' . $data[2] . '</FIELD3>'
.'</DATAITEM>';
}
$xml .= '</DATASET>';