\I am generating SQL file from CSV file, but have some string files with slashes and the value is like:
"aaa", "\", 111, 222, "bbb", "\", 333
The value between "\" will be generated as one string
'\", 111, 222, "bbb", "\', 333
But I hope to keep "\" as it should to be, or change it to NULL, like:
'NULL', 111, 222, 'bbb', 'NULL', 333
My code is like this:
while (($lineArr = fgetcsv($infile))!=FALSE){
foreach($lineArr as $line){
...
if ($line == '\\"')
$line = 'NULL';
...
}
}
This dose not work. I think $line =='\\"'
is not correct, but I do not know how to process the whole part between "\".
solution: I first change the array to string to process the '"\"', then change it back to array for further process.
while (($lineArr = fgetcsv($infile))!=FALSE){
$string = implode(",", $lineArr);
if (strpos($string,',\",')){
$sKeepSlash = str_replace(',\",', ",NULL,", $string);
$pLineArr = explode(',', $sKeepSlash);
}
foreach($lineArr as $line){
...
}
}