'데이터가 모든 탭이면 행을 인쇄하지 않는 경우'하는 방법?How to do '데이터가 모든 탭 ( t) 행을 인쇄하지 않는 경우'?
탭만 포함하는 행을 인쇄하지 않으려면 코드를 어떻게 변경해야합니까?
어떻게 든는 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>";
올바르게 코드를 들여하십시오. – Bluewind
코드가 들여 쓰여졌습니다. –