Built From Developers For Developers
» Kuikie.com » Snippets » PHP » Strings » PHP. Array to CSV
  Categories
  PHP
    Arrays
    Date & Time
    Files & Directories
    Globalization
    Images
    OOP
    Other
    Strings
    User Interface
 

PHP. Array to CSV

Comma Separated Values (CSV) files are largely used throughout the IT industry to store, transfer or backup data because of its lean, yet perfectly readable structure. The functions bellow show how to convert a PHP array to CSV format.

function array_to_csv($array) {
    ob_start();
    $fp = fopen('php://output', 'w');
    foreach ($array as $row) {
        fputcsv($fp, $row);
    }
    fclose($fp);
    return ob_get_clean();
}
 
©2012 Sinevia Ltd Terms of Use         Privacy Policy Valid XHTML 1.0 Transitional