Created
September 24, 2013 13:36
-
-
Save ibes/6684800 to your computer and use it in GitHub Desktop.
Custom Array to CSV function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* create CSV file from address data | |
* | |
* @var array Address Data | |
* @return string formated CSV file | |
*/ | |
function createCsv($address) { | |
// build array with headlines | |
$lines = array( | |
array('BestellNr', 'Bestelldatum', 'EndKdNr', | |
'LieferName', 'LieferAnsprech', 'LieferStrasse', 'LieferLand', | |
'LieferPlz', 'LieferOrt', 'Pos', | |
'ArtikelNr', 'Menge', 'Einzelpreis', 'Währung') | |
); | |
$i = 1; | |
foreach ($this->Bestelldaten as $Produktdaten) { | |
$Pos = $i; | |
$lines[] = array($this->BestellNr, $this->Bestelldatum, $this->EndKdNr, | |
trim($this->LieferName), trim($this->LieferAnsprech), trim($address['LieferStrasse']), $address['LieferLand'], | |
trim($address['LieferPlz']), trim($address['LieferOrt']), $Pos, | |
$Produktdaten['ArtikelNr'], $Produktdaten['Menge'], number_format( $Produktdaten['Einzelpreis'] , 2, ',', '' ), 'EUR'); | |
$i++; | |
} | |
unset($i); | |
// put array to csv | |
$outstream = fopen("php://temp", 'W+'); | |
foreach ($lines as $fields) { | |
fwrite($outstream,implode(';',$fields) . "\r\n"); | |
} | |
rewind($outstream); | |
$csv = stream_get_contents($outstream); | |
fclose($outstream); | |
$this->logger->logWrite("CSV-Datei generiert"); | |
return $csv; | |
} |
Maybe start the $csv with "\xEF\xBB\xBF" solves the problem, that the generated file is not UTF-8 by default.
As suggested: http://stackoverflow.com/questions/4839402/how-to-write-file-in-utf-8-format
Have to wait for feedback of Integralis...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Has to get a definition of utf-8 as chartset to work with Integralis