note 76895 added to function.fputcsv

From: Date: Sat, 04 Aug 2007 03:23:41 +0000
Subject: note 76895 added to function.fputcsv
Groups: php.notes 
Request: Send a blank email to php-notes+get-129167@lists.php.net to get a copy of this message
This function is a replacement for PHP 4. It basically takes an array you pass it, and creates a delimited string. If you want ot use the key as the field name, you can tell the second paramater to use the key. The last is the delimiter you want each value to be seperated by. Should be pretty straight forward. <?php function generate_csv_data($data,$use_key=false,$delm=',') { $output = NULL; if(is_array($data)) { if($use_key == false) { if(isset($data[0]) && is_array($data[0])) { foreach($data as $key) { $output .= implode($delm,$key); $output .= "\n"; } } else { $output .= implode("$delm", $data)."\n"; } } else { foreach($data as $key => $value) { $output .= "$key{$delm}$value\n"; } } } else { $output = $data; } if(empty($output)) { trigger_error('OUTPUT WAS EMPTY!', E_USER_ERROR); return false; } return $output; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 74.128.217.226 ---- Manual Page -- http://www.php.net/manual/en/function.fputcsv.php Edit -- https://master.php.net/note/edit/76895 Del: integrated -- https://master.php.net/note/delete/76895/integrated Del: useless -- https://master.php.net/note/delete/76895/useless Del: bad code -- https://master.php.net/note/delete/76895/bad+code Del: spam -- https://master.php.net/note/delete/76895/spam Del: non-english -- https://master.php.net/note/delete/76895/non-english Del: in docs -- https://master.php.net/note/delete/76895/in+docs Del: other reasons-- https://master.php.net/note/delete/76895 Reject -- https://master.php.net/note/reject/76895 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129167) next »