I have a project to build something that can download data from google sheets and put it into a sql database. As you might know, you can download google sheets documents using file_get_contents.
Now this returns me the spreadsheet csv as a string, but, of course, it ignores the line feed present in the csv files. But I really need the linefeed in order to input everything correctly into a mySQL database.
The CSV file (of my test spreadsheet) looks like this:
a,Test,Test 2,Test 3
1,"0,7491350111","0,571828352","0,9259991002"
2,"0,3248027034","0,8620383926","0,7291853676"
3,"0,5321335414","0,2950260548","0,02061110078"
4,"0,4981712566","0,3952212783","0,764936387"
5,"0,4268829571","0,269996733","0,1314054648"
6,"0,6468248522","0,3405109504","0,6273023046"
7,"0,1171196396","0,9859032656","0,9478148762"
8,"0,511933901","0,2980882701","0,1341947992"
9,"0,468416263","0,6052129434","0,2971030021"
10,"0,1615932418","0,3154291332","0,4234177369"
and my code for giving out a string currently looks something like this:
<?php
function getcsv() {
$spreadsheet_url = 'https://docs.google.com/spreadsheets/d/e/<YOURSPREADSHEETHERE>/pub?output=csv';
$csv = file_get_contents($spreadsheet_url);
print($csv);
}
?>
I won't show you my dozens of not working attempts to get an array.
As an output I would want something along this line:
Array([0] => Apple [1] => RED [2] => #D62433)
Array([0] => Orange [1] => ORANDE [2] => #FEB635)
Array([0] => Banana [1] => YELLOW [2] => #FEE492)
Array([0] => Grapes [1] => VIOLET [2] => #B370AD)
Array([0] => KIWI [1] => GREEN [2] => #9BA207)
Array([0] => Dates [1] => BROWN [2] => #922E2F)
How can I get this as an array as shown above, because I am clearly researching the wrong things.