Location: PHPKode > scripts > Class CSV > class-csv/classCSV.php
<?php
/**
*
* @author Walter Rodrigo de Sá Cruz
* @
*/
class CSV {
var $s='';

function CSV(){
 
  }

function escapeCSV($str){  
  if(preg_match("/[,\"\n\r]/", $str) > 0) {
    $str = '"'.str_replace('"', '""', $str).'"';
  }   
  
  if($str == ""){
    $str = '""';
  }
  
  return $str;
}

function toCSV ($t){

 $this->s ='';
 
  foreach($t as $key=>$item){
     $this->s = $this->s . "," . $this->escapeCSV($item);    
   }  

  $this->s = substr($this->s, 1); //remove a primeira vírgula  
  return $this->s;
  }
}
?>
Return current item: Class CSV