3v4l.org

run code in 300+ PHP versions simultaneously
<?php $file = date('dmY-His'); header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=visitors-$file.csv"); header("Pragma: no-cache"); header("Expires: 0"); $sql = "select id, ip, server, time, date from visitors"; $res = mysql_query($sql); $data = array(); $data[] = array('id', 'ip', 'server', 'time', 'date'); while ($row = mysql_fetch_array($res)) { $data[] = array_values($row); } $output = fopen("php://output", "w"); foreach ($data as $val) { fputcsv($output, $val); } fclose($output);

preferences:
47.46 ms | 402 KiB | 5 Q