This CSV files contains the following data:
ID,GeneId,Searchterm,Type
"4,1253246,0,Gene Ontology
","4,1253246,0,Pathway
","4,1253246,0,Interaction
"
Every line starts with "," for some reason. Is there a way to remove them using PHP?
The code I use to insert the data into the CSV file is the following:
Using a foreach loop to insert data into an array called $csv_data
$csv_data[] = $name. "," .$Id1. "," .$search_term. ",".$sort."\r\n";
Only keep the unique data to insert in CSV file
$csv_data = array_unique($csv_data, SORT_REGULAR);
fputcsv($demofile, $csv_data);
I didn't find out why the symbol quotes were added to each line but when I use the following code, the problem is solved.
fputcsv($demofile, array($name,$Id1,$search_term,$sort), ',', '"');
When I used $delimiter=',' or $enclosure='"', it wouldn't recognise parameters.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.