class_mcCsv.inc.php 1.12 KB
<?php
class mcCsv {


	/**
	 *	transform array to csv format and export as file
	 * 
	 * @since 20110920 @author n@mensch.coop
	 * @static
	 * @downgraded for php4
	 * 
	 * @param array $param_array
	 * @param type $param_filename 
	 * @param array $param_search
	 * @param array $param_replace 
	 */
	function exportArrayToCsv(array $param_array, $param_charset='utf-8', $param_filename='download.csv', array $param_search = array('"', ';'), array $param_replace = array("'", " ")) {
		$ausgabe = '';
		if (is_array($param_array) && count($param_array)!=0) {
			foreach ($param_array as $daten) {
				if (is_array($daten) == true) {
					foreach ($daten as $key => $value) {
						$ausgabe .= '"'.str_replace($param_search, $param_replace,	$daten[$key]).'";';
					}
				}
				$ausgabe .= "\n";
			}
		} else {
			$ausgabe .= '"no data;"';
		}		

		if (headers_sent() == false) {
			header("Content-type: text/csv; charset='.$param_charset");
			header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
			header("Content-Disposition: attachment; filename =".$param_filename);
			header('Pragma: no-cache');
		}
		echo $ausgabe;		
		
	}
}
?>