Exemplo n.º 1
0
 /**
  * Get the csv file as a string.
  *
  * @return string
  */
 public function asString()
 {
     $tmp = new \SplTempFileObject();
     foreach ($this->data as $row) {
         $tmp->fputcsv($row, $this->delimiter);
         if ($this->lineEnding !== "\n") {
             $tmp->fseek(-1, \SEEK_CUR);
             $tmp->fwrite($this->lineEnding);
         }
     }
     # Find out how much data we have written
     $length = $tmp->ftell();
     if ($length < 1) {
         return "";
     }
     # Reset the internal pointer and return all the data we have written
     $tmp->fseek(0);
     return $tmp->fread($length);
 }