---.csv. * Anything but letters, digits, _ and - is dropped from each part. */ public static function getFilename($aParts) { $aResult = ['analytics']; foreach($aParts as $sPart) { $sPart = preg_replace('/[^A-Za-z0-9_-]+/', '', (string)$sPart); if($sPart !== '') $aResult[] = $sPart; } return implode('-', $aResult) . '.csv'; } /** * Write a header row and rows to a stream: UTF-8 with a byte order mark (so spreadsheets * read it as UTF-8), commas, quotes doubled inside quoted cells. * * @param resource $rStream * @param array $aHeader column titles * @param array $aRows rows of cells */ public static function write($rStream, $aHeader, $aRows) { fwrite($rStream, "\xEF\xBB\xBF"); fputcsv($rStream, array_map([self::class, 'cell'], array_values($aHeader)), ',', '"', ''); foreach($aRows as $aRow) fputcsv($rStream, array_map([self::class, 'cell'], array_values($aRow)), ',', '"', ''); } } /** @} */