Fetch data from google spread-sheet with each row as a single sentence

Hi all,

I am going through a very critical situation where I cannot find bright ideas to work upon.

  1. I have an google spread sheet which contains few rows and columns.
  2. I want to combine the row together including its column value.(1 row with four columns which results to a single sentence)
  3. Simultaneously each row should form a single sentence from the google spread sheet.

My spread sheet path: https://docs.google.com/spreadsheets/d/1Z7_oRxlTIiKIND89sAXHbyTsz1mrTMNwejqkfk8y5P0/edit#gid=0

I dont know how to strt of with this and which function, code to prefer ?
Any kind of help is appreaciated.

Hello all,

Below is the code which I have tried so far and returns the output which I wanted. :slight_smile:


<?php
if ($_FILES["file"]["error"] > 0)
{
   echo "Error: " . $_FILES["file"]["error"] . "<br>";

echo "No files...!!!!!";

echo "<script>alert('No files...!!!!!');window.location.href='upload_file.php';</script>";
}
else
{
$a=$_FILES["file"]["tmp_name"];
$csv_file = $a; 

if (($getfile = fopen($csv_file, "r")) !== FALSE) {
        $data = fgetcsv($getfile, 1000, ",");
  while (($data = fgetcsv($getfile, 1000, ",")) !== FALSE) {
    //$num = count($data);
  //echo $num;
       //for ($c=0; $c < $num; $c++) {
           $result = $data;
       	$str = implode(",", $result);
       	$slice = explode(",", $str);
       
           $col1 = $slice[0];
           $col2 = $slice[1];
           $col3 = $slice[2];
		   echo $col1."".$col2."".$col3."<br/>";

}
}

}

?>

But now the case is that the files are been uploaded from .csv file.
I want the fetch data from directly “google spread sheet” URL.
In the baove code what will be the logic to add the spread sheet URl ?
any help is appreciated.

Thankyou…!!

You can use cURL to download the file to your server.

One of these will get you going,
https://www.google.com/search?q=php+curl+download+file&rlz=1C1CHFX_enUS576US576&oq=php+curl+download+file&aqs=chrome..69i57j0l5.9103j0j4&sourceid=chrome&es_sm=122&ie=UTF-8