在Excel文档中循环logging

我需要循环访问excel文件中的一些logging,并将它们作为HTML表格的标题输出,但我不知道什么是最好的方法,因为我是PHP新手。

每个列标题开始作为一个标题后跟一个索引,所以你有:

国家1,国家2,国家3 ….到国家50。

我想有一个更自动的方式来检索这些值而不是坚持

$ result。=“$ Country1”;

每一个都必须包含国家的ID也应该被转换成一个数组,即另一件事,所以他们不需要打印如果是这样的话,所以结果可能是

<th id="Country1">Value of Country1</th> <th id="Country2">Value of Country2</th> <th id="Country3">Value of Country3</th> <th id="Country8">Value of Country8</th> <th id="Country24">Value of Country24</th> <th id="Country30">Value of Country30</th> 

什么是最好的“代码灯”的方法来做到这一点?

问候!

像这样的东西应该工作:

 <?php $handle = @fopen("/tmp/myfile.csv", "r"); if ($handle) { // first line should be the header, we make it an array of strings if ( ($buffer = fgets($handle, 4096)) !== false ) $headers[] = explode(",", $buffer); else echo "Error: empty file...\n"; // second line should be the values, for each line we output the xml markups while ( ($buffer = fgets($handle, 4096)) !== false ) { $values[] = explode(",", $buffer); if( count($headers) != count(values) ) echo "Error: the 2 lines do not have same number of columns...\n"; else { for( $i = 0 ; $i < count($headers) ; $i++ ) echo "<th id='".$headers[$i]."'>".$values[$i]."</th>\n"; } } else echo "Error: second line empty...\n"; if ( !feof($handle) ) echo "Erreur: fgets() failed...\n"; fclose($handle); } ?>