этот код создает файл csv. Однако я не распечатывал запятые в полях, потому что они используются в качестве разделителя (см. строку 22). Теперь я хочу удалить (возвраты каретки и новые строки) из полей. Добавление $somecontent .= str_replace("\n", "", $val); в строке 23 не работает. Любые идеи?
@chmod($export_csv, 0777);
$fe = @fopen($export_csv."/export.csv", "w+");
if($fe){
$somecontent = "";
$fields_count = 0;
// print field headers
$db->query($sql_view);
if($row = $db->fetchAssoc()){
foreach($row as $key => $val){
if($fields_count++ > 0) $somecontent .= ",";
$somecontent .= ucfirst($key);
}
}
$somecontent .= "\n";
// print field values
$db->query($sql_view);
while($row = $db->fetchAssoc()){
$fields_count = 0;
foreach($row as $key => $val){
if($fields_count++ > 0) $somecontent .= ",";
$somecontent .= str_replace(",", "", $val);
$somecontent .= str_replace("\n", "", $val);
}
$somecontent .= "\n";
}
// write some content to the opened file.
if (fwrite($fe, $somecontent) == FALSE) echo 'file_writing_error'." (export.csv)";
fclose($fe);
}