【发布时间】:2012-10-14 01:07:19
【问题描述】:
我有一个简单的小脚本,它可以抓取 XML 并将其转换为 CSV。但是它不写标题。有谁知道标题怎么写?
$file='example.xml';
if (file_exists($file)) {
$xml = simplexml_load_file($file);
$f = fopen('newfile.csv', 'w');
foreach ($xml->Information as $information) {
fputcsv($f, get_object_vars($information),',','"');
}
fclose($f);
}
这会将<Information> 的子元素的所有内容放在 Excel 的漂亮列中。但它不会将元素名称写为 CSV 标题。
有什么想法可以编辑脚本以包含标题吗?
谢谢
迈克
【问题讨论】:
标签: php xml csv simplexml fopen