분류 php

CSV Export

컨텐츠 정보

  • 조회 347 (작성일 )

본문

<?php
/*
 *  Export your array to csv
 *  Created by Leo Watanabe <leow_74 at yahoo dot com> - August 2003
 */
 
// Caution: $data MUST be an array of array
function convertToExcelCSV($data) {
  // Sorry, not an array...
  if(!is_array($data)) { return ''; }
  $csv = '';
  foreach($data as $record) {
    // all record must be an array
    if(is_array($record)) {
      // convert this record to csv
      $csv .= convertArrayToCSV($record) . "rn";
    }
  }
  return $csv;
}
 
// convert an array to csv
function convertArrayToCSV($record) {
  // need to test because I don't have privative functions :(((
  if(!is_array($record)) { return ''; }
  $ret = '
php