<?php
/*header('Content-Encoding: ISO-8859-1');
header('Content-Type: text/csv; charset=ISO-8859-1');
header('Content-Disposition: attachment; filename=clientes_ativos'.date('d_m_Y_h_i_s').'.csv');
header('Content-Transfer-Encoding: binary');

header('Pragma: public');
header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');

// create a file pointer connected to the output stream*/
if ($format == 'csv') {
	$output = fopen('php://output', 'w');
	fputcsv($output, array('Email'));
	foreach ($data as $cliente) {
		$email = $cliente->CLI_EMAIL;
		$info  = array(strtolower($email));
		if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
			fputcsv($output, $info);
		}
	}
} else {
	foreach ($data as $cliente) {
		$email = $cliente->CLI_EMAIL;
		if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
			echo strtolower($email).',';
		}
	}
}
