$rows */ public function generate(array $header, array $rows): string { $file = new \SplTempFileObject(); $file->fputcsv( $header, ';', '"', '\\' ); foreach ($rows as $item) { $file->fputcsv($item, ';', '"', '\\'); } $file->rewind(); $content = ''; while (! $file->eof()) { $content .= $file->getCurrentLine(); $file->next(); } return $content; } }