Use search engines to search for code samples such as http://codestips.com/php-xml-to-csv/
To create a csv file from xml in PHP 5.0 is very simple, we just need to write a few lines.
We will use the SimpleXML extension that ships with PHP 5.0.
SimpleXML reads all xml into an object, which we can iterate through its properties. To write csv to the output file, we will use fputcsv.
fputcsv formats the string as csv and writes it to a file.
Suppose we have this xml called cars.xml:
<?xml version='1.0'?>
<cars>
<car>
<color>blue</color>
<price>2000</price>
</car>
<car>
<color>red</color>
<price>10000</price>
</car>
<car>
<color>black</color>
<price>5000</price>
</car>
</cars>
xml, simplexml_load_file, csv:
$xml = simplexml_load_file($filexml);
, fputcsv, , . , csv:
foreach ($xml->car as $car)
fputcsv($f, get_object_vars($car),',','"');
, xml csv php 5.0:
<?php
$filexml='cars.xml';
if (file_exists($filexml)) {
$xml = simplexml_load_file($filexml);
$f = fopen('cars.csv', 'w');
foreach ($xml->car as $car) {
fputcsv($f, get_object_vars($car),',','"');
}
fclose($f);
}
?>