I'm having trouble viewing a csv file. My intention is that I can use the Excel command "data to column" and stay line by line, but the file has skipped line making it impossible. The code was made based on another example here even posted by an adm.
date_default_timezone_set('America/Sao_Paulo');
ini_set('memory_limit', '12000M');
require_once($_SERVER['DOCUMENT_ROOT']."/administrator/lib/connection.php");
//echo "<script type=\"text/javascript\"> window.open(\"http://www.tometoo.com.br/generateCSV2.php\", \"_blank\")</script>";
$PDO = Database::Connect();
$SQL = "SELECT idpost, idcomment, cm_id_author, pg_name, ps_date, cm_date, ps_message, cm_name_author, cm_message, pss_likes, pss_shares, pss_comments, cms_like, cms_reply
from fb_post
INNER JOIN fb_pssummary ON pss_idpost = idpost
INNER JOIN fb_page ON ps_idpage = idpage
INNER JOIN fb_comment ON cm_idpost = idpost
INNER JOIN fb_cmsummary ON cms_idcomment = idcomment
where ps_date between '2016-09-01 00:00' and '2016-09-01 23:59:59'
ORDER BY ps_date ASC";
$SQL = $PDO->prepare($SQL);
$SQL->execute();
$result = $SQL->fetchAll(PDO::FETCH_ASSOC);
function array_para_csv(array &$array)
{
if (count($array) == 0) {
return null;
}
ob_start();
$df = fopen("php://output", 'w');
fputcsv($df, array_keys(reset($array)));
foreach ($array as $row) {
fputcsv($df, $row);
}
fclose($df);
return ob_get_clean();
}
function cabecalho_download_csv($filename) {
// desabilitar cache
$now = gmdate("D, d M Y H:i:s");
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header("Last-Modified: {$now} GMT");
// forçar download
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
// disposição do texto / codificação
header("Content-Disposition: attachment;filename={$filename}");
header("Content-Transfer-Encoding: binary");
}
cabecalho_download_csv("setembro_1_1M_1_parte" . date("Y-m-d") . ".csv");
echo array_para_csv($result);
the output has been this way in excel 229151370439618_1206843959337016,1206843959337016_1206850609336351,1063115217101837, CartaCapital, "2016-09-01 00:15:31", "2016-09-01 00:27:42", "POLICE VIOLENCE The center of Sao Paulo became a veritable war-chamber tonight, from the moment that Military Police decided to disperse the demonstration against the coup from the middle of it. The effect was the dispersion of protesters to various corners and a real hunt promoted by police based bombs and rubber bullets. According to information, a young woman is currently in the Clinic Hospital with the strong possibility of having lost sight of an eye and a photographer had her work equipment broken and was detained. At the moment, not even the photographer's lawyers were informed about the reason for the arrest Images by Tadeu Amaral
Coup #Impeachment, "" Marco Antonio Camelo "," Capital letter defends bandits. ", 418,76,263,4,0
Please ignore facebook content that has nothing to do with my opinion. As you can see beyond the accent has the problem of the lines.