Created
March 28, 2014 16:25
-
-
Save kostajh/9836902 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$headers = array(); | |
foreach ($xml->ROW->children() as $field) { | |
$headers[] = $field->getName(); | |
} | |
$csv_filename = str_replace('xml', 'csv', $filename); | |
$file = $this->getCsvDirectory() . '/' . $csv_filename; | |
if (file_exists($file)) { | |
unlink($file); | |
} | |
$csv = fopen($file, 'w'); | |
fputcsv($csv, $headers, ',', '"'); | |
foreach ($xml as $entry) { | |
$data = get_object_vars($entry); | |
// Decode HTML entities. | |
$sanitized_data = array(); | |
foreach ($data as $key => $datum) { | |
$sanitized_data[$key] = html_entity_decode($datum, ENT_COMPAT, 'UTF-8'); | |
} | |
fputcsv($csv, $sanitized_data, ',', '"'); | |
} | |
fclose($csv); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment