![](/img/trans.png)
[英]My slider only shows 1st and 3rd slider but not the 2nd and 4th slider for table
[英]CSV to TSV (but only 1st and 3rd line) or to a table
我有这样的CSV文件:
Name,7680,Value,7684,7685,7688,7689,7690,7697,7698,7699,7700,7701,7702,7703,7704,7710,7711,7712,7733,7737
140101_130002,2,50948,1,21801,316,316,327,500,887,903,900,897,641,654,673,332,310,324,3,6,0,0
140101_133002,2,51046,1,21849,317,316,327,500,887,899,902,896,645,654,678,335,317,325,3,6,2,2
140101_134501,2,51096,1,21874,315,315,326,499,886,899,898,894,638,651,671,335,314,325,3,6,3,3
第一行是名称,我想将第一个值和第三个值取为TSV,或者至少将它们放到html表中,而不是所有值。
例如,我需要这个:
Name Value
140101_130002 50948
140101_133002 51046
请帮忙。
此代码将执行您想要的操作。
$csv_file = "yourfile.csv"; // Name of your CSV file
$csvfile = fopen($csv_file, 'r');
$name_value=array();
if(is_file($csv_file)){
fgets($csvfile); // read and ignore the first line
//if you want to show "Name Value" at beginning of the table, just comment this line
while (!feof($csvfile)){
$data = fgetcsv($csvfile,4096,",");
$name_value[]=array($data[0],$data[2]);
}
fclose($csvfile);
echo "<table>";
foreach($name_value as $data_to_show) {
echo "<tr><td>".$data_to_show[0]."</td><td>".$data_to_show[1]."</td></tr>";
}
echo "</table>";
}else die('File no good!');
它将回显一个表,其中包含:
140101_130002 50948
140101_133002 51046
140101_134501 51096
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.