note 112152 deleted from language.oop5 by googleguy

From: Date: Fri, 10 May 2013 11:07:27 +0000
Subject: note 112152 deleted from language.oop5 by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-194771@lists.php.net to get a copy of this message
Note Submitter: hafiz_fp_bd at yahoo dot com ---- <?php /** * Description of bscsvarray class for array to csv and csv to array convert * @author Md.Hafizur Rahman */ class bscsvarray { var $csvtoarray_tmp_file_name; var $csvtoarray_buffer; var $csvtoarraystr=array(); var $csvtoarrayresult=array(); var $arraytocsv_buffer; public function __construct() { $this->csvtoarray_tmp_file_name=''; $this->arraytocsv_buffer=''; $this->csvtoarray_buffer=''; } public function csvtoarray($fname) //CSV file-> Multi Dimentional Aaary { if (($this->csvtoarray_tmp_file_name = fopen($fname, "r")) !== FALSE) { while (($this->csvtoarray_buffer = fgetcsv($this->csvtoarray_tmp_file_name,100000, ",")) !== FALSE) { $this->csvtoarraystr=array(); foreach ($this->csvtoarray_buffer as $value) { array_push($this->csvtoarraystr,$value); } array_push($this->csvtoarrayresult,$this->csvtoarraystr); } fclose($this->csvtoarray_tmp_file_name); } return $this->csvtoarrayresult; } public function arraytocsv($fname,$list=array()) //Multi Dimentional Aaary ->CSV file { if(($this->arraytocsv_buffer = fopen($fname, 'w'))!== FALSE ) { foreach ($list as $fields) { fputcsv($this->arraytocsv_buffer, $fields); } fclose($this->arraytocsv_buffer); } } public function __destruct() { return 0; } } $file=new bscsvarray(); $file->csvtoarray('test.csv'); // return array $list=array( array('ID','NAME','ADDRESS'),array('ID001','Hafiz','Bangladesh')); $file->arraytocsv('xyz.csv',$list); // return csv file ?>

« previous php.notes (#194771) next »