如何将echo表标题添加到当前代码中?

时间:2012-04-23 15:37:31

标签: php html

如何将回显表标题添加到当前代码中?

由于$ lines [0] else echo {{{$ I}如果有人可以提供帮助的话,那我就会失去多个空<th>,所以我很少丢失。

<tr>

schedule.txt示例:

<th>

1 个答案:

答案 0 :(得分:1)

不太确定我是否正确地阅读了您的问题,但这是您需要的吗?

function schedule_gen()
{
//set file
$filename='schedule.txt';
//open
$handler=fopen('schedule.txt','r');
//read through file
$file=fread($handler,filesize($filename));

//start table creation
echo "<table id='schedule_table'>"; 

//split into array by return\linefeed
$lines=explode("\r\n",$file);

//loop through rows
for($i=0;$i<count($lines);$i++) 
{ 
//if not blank then print row
if($lines[$i]!=""&&$lines[$i]!=" ")
{
$t_type="td";
if($i==0){$t_type="th";}

//split into array by commas
$items=explode("\t",$lines[$i]);
//loop through cells 
for($j=0;$j<count($items);$j++) 
{ 
//if not blank then print cell
if($items[$j]!=""&&$items[$j]!=" ")
{
echo "<$t_type class='schedule_cell'>".$items[$j]."</$t_type>"; 
}
} 
echo "</tr>"; 
}
} 
echo "</table>"; 
//end table creation

fclose($handle);
//close file 
}