[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 3 require_once 'Horde/Data/csv.php'; 4 5 /** 6 * Horde_Data implementation for Outlook comma-separated data (CSV). 7 * 8 * $Horde: framework/Data/Data/outlookcsv.php,v 1.3.10.3 2005/10/18 11:01:04 jan Exp $ 9 * 10 * @package Horde_Data 11 */ 12 class Horde_Data_outlookcsv extends Horde_Data_csv { 13 14 /** 15 * Builds a CSV file from a given data structure and returns it as a 16 * string. 17 * 18 * @param array $data A two-dimensional array containing the data 19 * set. 20 * @param boolean $header If true, the rows of $data are associative 21 * arrays with field names as their keys. 22 * 23 * @return string The CSV data. 24 */ 25 function exportData($data, $header = false, $export_mapping = array()) 26 { 27 if (!is_array($data) || count($data) == 0) { 28 return ''; 29 } 30 31 $export = ''; 32 $eol = "\r\n"; 33 $head = array_keys(current($data)); 34 if ($header) { 35 foreach ($head as $key) { 36 if (!empty($key)) { 37 if (isset($export_mapping[$key])) { 38 $key = $export_mapping[$key]; 39 } 40 $export .= '"' . $key . '"'; 41 } 42 $export .= ','; 43 } 44 $export = substr($export, 0, -1) . $eol; 45 } 46 47 foreach ($data as $row) { 48 foreach ($head as $key) { 49 $cell = $row[$key]; 50 if (!empty($cell) || $cell === 0) { 51 $cell = preg_replace("/\"/", "\"\"", $cell); 52 $export .= '"' . $cell . '"'; 53 } 54 $export .= ','; 55 } 56 $export = substr($export, 0, -1) . $eol; 57 } 58 59 return $export; 60 } 61 62 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |