×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Gábor Papp
Added: Nov 1, 2021 5:56 AM
Views: 2260
Tags: no tags
  1. $lista=$s_db->GetArray("SELECT ".$mlist." FROM ".P."termek ORDER BY id ASC LIMIT 0,20");
  2.  
  3. for ($i=0; $i<count($lista); $i++) {
  4.     $lista[$i]['szoveg_kicsi']=nl2br($lista[$i]['szoveg_kicsi']);
  5.     $lista[$i]['szoveg_kicsi']=preg_replace( "/\r|\n/","",$lista[$i]['szoveg_kicsi']);
  6. }
  7.  
  8. $mezl=[];
  9. $mezl['id']=['name'=>'id','url'=>'id'];
  10. $mezl['aktiv']=['name'=>'aktiv','url'=>'aktiv'];
  11. $mezl['kiemelt']=['name'=>'kiemelt','url'=>'kiemelt'];
  12. $mezl['nev']=['name'=>'nev','url'=>'nev'];
  13. $mezl['url']=['name'=>'url','url'=>'url'];
  14.  
  15. $out='csv';
  16. if ($out=='csv') {
  17.     header('Content-Type: text/csv; charset=utf-8;');
  18.     // header('Content-type: application/ms-excel');
  19.     header('Content-Disposition: attachment; filename="szabokandallo-'.$csvdata.'.csv"');
  20.     $colums='';
  21.     foreach ($mezl as $key=>$value) {
  22.         $colums.=$key.';';
  23.     }
  24.     $colums=substr($colums,0,strlen($colums)-1)."\n";
  25.    
  26.     $outarray_full=$colums.PHP_EOL;
  27.     for ($i=0; $i<count($lista); $i++) { $one=$lista[$i];
  28.         $outarray=[];
  29.         foreach ($mezl as $key=>$value) {
  30.             $outarray[]=$one[$key];
  31.         }
  32.         $outarray_full.=implode(";",$outarray).PHP_EOL;
  33.     }
  34.     echo "\xEF\xBB\xBF"; // ez kell ahhoz, hogy az excel jol jelenitse meg "UTF-8 + BOM"
  35.     echo $outarray_full; exit;
  36. }