I'm doing a simple **fwrite**
in a csv file writing one line afte the other:
//Clean maybe empty entries of last winners
$cleaned = array();
$tick = 0;
$debug = "";
if (($fh = fopen(LAST_WINNERS_PATH, 'r+b')) !== FALSE) {
if (flock($fh, LOCK_EX)) {
while (($row = fgetcsv($fh, 300, ';')) !== FALSE) {
$tick++;
foreach ($row as $key => $value) {
$row[$key] = stripslashes($value);
}
if ($row[0] != '') {
array_push($cleaned, $row);
}
}
array_reverse($cleaned);
ftruncate($fh, 0);
$count = count($cleaned);
foreach ($cleaned as $key => $row) {
$string = implode(";", $row);
if ($key < $count -1) {
$string .= PHP_EOL;
}
fwrite($fh, $string);
}
flock($fh, LOCK_UN);
} else {
}
fclose($fh);
} else {
}
Now I have two questions:
Everything is in utf-8, but the csv file converts every time back to ANSI, when writing to it. Why and what can be don to prevent this?
In front of the first line every time several whitespaces are added. How to avoid that?