如何做'如果数据是所有选项卡不打印行'?
如果我不想打印仅包含制表符的行,我应该如何更改我的代码?
我想以某种方式使用preg_match,即preg_match('#(/'t+/)#',$lines[$i])
但是这会破坏我的代码,因为它将制表符分隔的文件变成表格,删除开头的 <tr>
标记使其以这种方式工作(没有制表符行),但我不能在<tr>
上放一个类。
.PHP:
echo "<table id='schedule_table'>";
//split into array by return'linefeed
$lines=explode("'r'n",$file);
//replace digits with class
$lines=preg_replace('#('d+)#','<span class="table_digit">$1</span>',$lines);
//loop through rows
for($i=0;$i<count($lines);$i++)
{
//if not blank then print row
if($lines[$i]!=""&&$lines[$i]!=" "&&$lines[$i]!=null)
{
echo "<tr class='schedule_row' value='$lines[$i]'>";
//if row is 0 cell type is header
$cell_type="td";
$cell_class="schedule_cell";
if($i==0)
{
$cell_type="th";
$cell_class="schedule_hcell";
}
//end if
//split into array by tabs
$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 "<$cell_type class=$cell_class>".$items[$j]."</$cell_type>";
}
}
echo "</tr>";
}
}
echo "</table>";
锚定你的正则表达式:
preg_match('/^'t+$/', $line)
在代码中将此正则表达式用作:
if ($lines[$i]!="" && $lines[$i]!=" " && !preg_match('/^'t+$/', $line[$i]))