icubesire

revenuehits

Search in Desigs Guru

Tuesday, October 7, 2014

Java Samples - Tutorials, articles and code samples

Java Samples - Tutorials, articles and code samples

Link to Programming Tutorials, articles, and code samples

Convert XML to CSV in PHP

Posted: 05 Oct 2014 09:00 AM PDT

Output XML string as CSV with first row as column headers

PHP code to write to a CSV file for Microsoft Applications

Posted: 05 Oct 2014 09:00 AM PDT

I've created a function for quickly generating CSV files that work with Microsoft applications. In the field I learned a few things about generating CSVs that are not always obvious. First, since PHP is generally *nix-based, it makes sense that the line endings are always \n instead of \r\n. However, certain Microsoft programs (I'm looking at you, Access 97), will fail to recognize the CSV properly unless each line ends with \r\n. So this function changes the line endings accordingly. Secondly, if the first column heading / value of the CSV file begins with uppercase ID, certain Microsoft programs (ahem, Excel 2007) will interpret the file as being in the SYLK format rather than CSV, as described here: http://support.microsoft.com/kb/323626

PHP code to write to a CSV file from MySQL query

Posted: 05 Oct 2014 09:00 AM PDT

Utility function to output a mysql query to csv with the option to write to file or send back to the browser as a csv attachment.

PHP code to import from CSV file to MySQL

Posted: 05 Oct 2014 09:00 AM PDT

After playing a while, I'm confident the following replacement function works in all cases, including the ones for which the native fputcsv function fails. If fputcsv fails to work for you (particularly with mysql csv imports), try this function as a drop-in replacement instead.

No comments:

Post a Comment

Thanks

LinkWithin

Related Posts Plugin for WordPress, Blogger...