I am going to export an output of a query in a text file (not CSV file) via PHP using fputcsv
function, but when I open the text file, extra double-quotes (") are added at the start & end, and also in the middle:
"SET: NEID=35;"
"ADD OPDNAL:ENTR=571,DIGIT=""703901943"",NANNAT=ALL,NAME=""CallingFilter"",RATIO2=0;"
This is the result that I want:
SET: NEID=35;
ADD OPDNAL:ENTR=571,DIGIT="703901943",NANNAT=ALL,NAME="Calling Filter",RATIO2=0;
My code is as below:
$sql="select 'SET: NEID=35;' as ACC_OFFNET from dual
union all
SELECT ACC_OFFNET FROM JLD_ADD WHERE ACC_OFFNET NOT IN (SELECT ACC_OFFNET FROM JLD_ADD_BK)
union all
select 'syn' as ACC_OFFNET from dual";
$result = odbc_exec($connect_raidprd, $sql) or die("Couldn't execute query! ".odbc_errormsg());
$date=date('Y-m-d H:ia',time());
$update = str_replace(':','-',$date);
$filenameJLD = "JLD-ADD-". $update.".csv";
$handle = fopen($filenameJLD, 'w+');
while ($row =odbc_fetch_array($result)) {
fputcsv($handle,array($row['ACC_OFFNET']));
}
// Finish writing the file
fclose($handle);
odbc_close($connect_raidprd);
Alternatively, is it possible for fwrite
to accept array as the argument?
as this. while ($row =odbc_fetch_array($result)) { $data=implode("
",array($row['ACC_OFFNET'])); fwrite($handle,$data); } – Meena May 01 '18 at 07:39