2012-04-25 2 views
0

'데이터가 모든 탭이면 행을 인쇄하지 않는 경우'하는 방법?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>"; 
+0

올바르게 코드를 들여하십시오. – Bluewind

+0

코드가 들여 쓰여졌습니다. –

답변

4

앵커 정규식 :

preg_match('/^\t+$/', $line) 

사용하는 코드에서이 정규식과 같이이 쉽게 읽을 수 그래서

if ($lines[$i]!="" && $lines[$i]!=" " && !preg_match('/^\t+$/', $line[$i])) 
+0

그래서 나는 여기 그것을 시도했지만 작동하지 않았다. : '$ temp = preg_match ("/^\ t + $/gi", $ lines [$ i]); // 공백이 아니라면 행을 인쇄하십시오 if ($ lines [$ i]! = ""&& $ lines [$ i]! = ""&& $ lines [$ i]! = $ temp) {do code} ' –

+0

@Event_Horizon : 제 편집을보세요. – Toto

+0

고맙습니다. M42, 그게 효과적이었습니다. 그 경기는 "모든 탭의 시작부터 모든 줄 끝까지 맞 춥니 다"라는 말이 맞습니까? –