2016-10-08 6 views
0
<?php 
// link to Google Docs spreadsheet 
$url='https://docs.google.com/spreadsheets/d/1_4d-MPxTUOVZbxTOlhjXv1ebTlBPQ-_JrYUlS1rqX5Q/pub?output=csv'; 

// open file for reading 
if (($handle = fopen($url, "r")) !== FALSE) 
{ 
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) 
    { 
     $totalrows = count($data); 
     for ($row=0; $row<=$totalrows; $row++) 
     { 

      if ((strlen($data[$row])>0)) 
      { 
       echo '<dt><span class="icon"></span>'.$data[$row].'</dt><dd>'.$data[$answer].'</dd>'; 
      } 
     } 
    } 
    fclose($handle); 
} 
?> 

Googleのシートファイルから各セルを取得しますが、このコードを1つずつエコーします。それらを1つの文字列に連結し、その文字列をjsスクリプトに渡す必要があるので、それらを一度にすべてエコーする必要があります。私は多くのPHPを知らないので、エコーラインを解読するのに苦労している。エコーを組み合わせて文字列を有効なhtmlとしてエコーします

答えて

1

あなたは、変数を定義し、それに文字列を追加することができます:私は+ =のことをしようとしていた

<?php 
// link to Google Docs spreadsheet 
$url='https://docs.google.com/spreadsheets/d/1_4d-MPxTUOVZbxTOlhjXv1ebTlBPQ-_JrYUlS1rqX5Q/pub?output=csv'; 

// Define variable which will hold your data. 
$html = ""; 

// open file for reading 

if (($handle = fopen($url, "r")) !== FALSE) 
{ 
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) 
    { 
     $totalrows = count($data); 
     for ($row=0; $row<=$totalrows; $row++) 
     { 

      if ((strlen($data[$row])>0)) 
      { 
       // Append your data to $html variable 
       $html .= '<dt><span class="icon"></span>'.$data[$row].'</dt><dd>'.$data[$answer].'</dd>'; 
      } 
     } 
    } 
    fclose($handle); 
} 

//Do whatever you want with $html variable. 
?> 
+0

感謝を。今はすべてがより意味をなさないものになります。 – MickDom

+0

+ = JavaScriptで動作します。 –

関連する問題