[PHP] csv to xml
2015-05-28 14:51
369 查看
<?php error_reporting(E_ALL | E_STRICT); ini_set('display_errors', true); ini_set('auto_detect_line_endings', true); $inputFilename = 'input.csv'; $outputFilename = 'output.xml'; // Open csv to read $inputFile = fopen($inputFilename, 'rt'); // Get the headers of the file $headers = fgetcsv($inputFile); // Create a new dom document with pretty formatting $doc = new DomDocument(); $doc->formatOutput = true; // Add a root node to the document $root = $doc->createElement('rows'); $root = $doc->appendChild($root); // Loop through each row creating a <row> node with the correct data while (($row = fgetcsv($inputFile)) !== FALSE) { $container = $doc->createElement('row'); foreach ($headers as $i => $header) { $child = $doc->createElement($header); $child = $container->appendChild($child); $value = $doc->createTextNode($row[$i]); $value = $child->appendChild($value); } $root->appendChild($container); } echo $doc->saveXML();
相关文章推荐
- PHP xml to csv
- PHP 读写 CSV 、XML 文件: SimpleExcel
- Php的数组转换成XML(php Array to Xml)
- LINQ to XML 从逗号分隔值 (CSV) 文件生成 XML 文件
- PHP如何自动识别第三方Restful API的内容,自动渲染成 json、xml、html、serialize、csv、php等数据
- Insight into DOMDocument - how to convert data from XML to array in PHP
- PHP XML To Array,将XML转换为数组
- PHP XML To Array将XML转换为数组
- Export Silverlight DataGrid to Excel XML/CSV
- 导出 Silverlight DataGrid to Excel XML/CSV
- 导出 Silverlight DataGrid to Excel XML/CSV
- php csv to array (csv 转数组)
- CSVToXML.jar CSV to XML的方法
- PHP XML To Array,将XML转换为数组
- [PHP] To display some attribute of the node in the XML document.
- Spring Batch Example – XML File To CSV File(六)
- php csv to array (csv 转数组)
- Google Merchant How To Setup A Live XML Data Feed With MySql and PHP
- PHP Fatal error: Uncaught Error: Call to undefined function xml_parser_create() 引发的问题
- Android Studio插件之Android Strings.xml To CSV Converter(失效)