I've got a HTML form, which I need to store in DB, then write it to .csv and .txt . Everything work well, except the txt output give me some bad string.
fputcsv function:
private function fputcsv_custom1($fp, $array, $eol)
{
fputcsv($fp, $array, ';');
if ("\r\n" != $eol && fseek($fp, -1, SEEK_CUR) === 0)
{ fwrite($fp, $eol . "\r\n"); }
}
Controller:
$peoples = OnlineSz::all()->toArray();
$file = fopen("online_hotel.csv", "w+");
$file1 = fopen("online_hotel.txt", "w+");
array_keys($peoples);
foreach ($peoples as $key => $array) {
$this->fputcsv_custom($file, $array, ';');
$this->fputcsv_custom1($file1, $array, ';');
}
fclose($file);
fclose($file1);
It generates me 2 file, which separated by ; and the last value give a \r\n to new line.
The txt output is the next:
53;"New test";Worker;test;test;4000;test;test;06123456789;test;0;0;CC;;0;0;
If the string contain whitespace, it's stored by " " , how can i remove this quotes? Or how can i replace the quotes only this column from an array?
Thanks for the help!
EDIT
If i replace the space between 2 word, the quotes are not there, but what can i do if i need the space between the string?
Controller:
$this->fputcsv_custom($file4, str_ireplace(chr(32), '/',$user), ';');
$this->fputcsv_custom1($file5, str_ireplace(chr(32), '/',$user), ';');
Output:
53;New/test;Alkalmazott;test;test;4000;test;test;06123456789;0;0;CC;0;0;
But this i wrong, because the /, and if i replace it to chr(32), the quotes will be there.
Any solution?