|  | 
	                
  
    | 
	 
        ช่วยแก้ไขการ อ่าน text file และแสดงข้อมูล ให้ font คนละสีค่ะ     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | ไฟล์ text หน้าตาเป็นแบบนี้ค่ะ 
  
 อยากให้ แสดงค่าที่ขึ้นต้นด้วยเลข 4
 
 ทีละ 3 ข้อมูล เป็นสีสลับกันค่ะ
 
 1ชุดมี ข้อมูล 3 ตัว
 ชุดแรก เป็นสี แดง
 ชุดที่2 เป็นสีน้ำเงิน
 
 สลับกันไปค่ะ
 
 ข้อมูลจะสลับกันไปแบบนี้อะค่ะ มีประมาณ 1000 ข้อมูล
 
 
 ผลลัพท์อยากให้ออกเป็น
 41206.44150686377
 41205.0
 41204.26708984375
 
 41203.05810546875
 41201.34423828123
 41195.0
 
 
 ตอนนี้ลองเขียนโคดขึ้นมา แต่มันแสดงที่ละ 3 ไม่ได้อะค่ะ มันแสดงหมดทุกข้อมูลเลย ช่วยแนะนำทีค่ะ
 Code (PHP)
 
 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
<body>
<?
   $Qdata = "test.txt" ;
   $assay = file($Qdata) ;
while (list ($line_num, $line) = each ($assay)) 
 {
   $Xref = substr($line,0,12)  ;
   
  
   if ($Xref == "AcDbPolyline")
	{
	while (list ($line_num, $line) = each ($assay)) {  
	 $rex = substr($line,1,2)  ;
	 if($rex == "10")
     {
		 
		 
	 while (list ($line_num, $line) = each ($assay) ) {  
	         
		$rex2 = substr($line,0,1)  ;
		
		if($rex2 == "4"){
			$rex3 = substr($line,0,17)  ;
			$x = $rex3;
			
			echo "$x <br> ";
			
			
		                 }
	
	 }
					   
	 }
	 
	 }
	 
   }
	
 }
 
 
 
   ?>
   
   
</body>
</html>
 มันแสดงทุกค่าแบบนี้ค่ะ ไม่แยกทีละ 3
 41206.44150686377
 41205.0
 41204.26708984375
 41203.05810546875
 41201.34423828123
 41195.0
 41194.60400390623
 41193.40966796873
 41191.7236328125
 41185.0
 41184.92138671875
 41183.74267578125
 
 
  
 
 
 Tag : PHP, JavaScript
 
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2015-12-16 14:28:46 | By :
                          sammam | View :
                          928 | Reply :
                          6 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (PHP) 
 $count = 0;
if($rex2 == "4"){
$x = substr($line,0,17)  ;
if(($count % 6) < 3){
echo "<red>$x</red> <br> ";
}else{
echo "<blue>$x</blue> <br> ";
}
$count +=1;
}
 * ประมาณนี้ล่ะมั้ง
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-12-16 14:42:56 | By :
                            noMerzy |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (PHP) 
 $Qdata = "test.txt" ;
   $assay = file($Qdata) ;
while (list ($line_num, $line) = each ($assay)) 
 {
   $Xref = substr($line,0,12)  ;
   
  
   if ($Xref == "AcDbPolyline")
	{
	while (list ($line_num, $line) = each ($assay)) {  
	 $rex = substr($line,1,2)  ;
	 if($rex == "10")
     {
		 
		 
	 while (list ($line_num, $line) = each ($assay) ) {  
	         
		$rex2 = substr($line,0,1)  ;
		
		$count = 0;
        if($rex2 == "4"){
        $x = substr($line,0,17)  ;
        if(($count % 6) < 3){
        echo "<red>$x</red> <br> ";
        }else{
       echo "<blue>$x</blue> <br> ";
          }
          $count +=1;
         }
	
	 }
					   
	 }
	 
	 }
	 
   }
	
 }
 
 ยังไม่ได้อะค่ะ  ค่าที่ได้เป็นแสดงทุกข้อมูลเหมือนเดิม T_T
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-12-16 14:50:05 | By :
                            sammam |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ช่วยหนูด้วยค่ะ T_T 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-12-16 15:55:53 | By :
                            sammam |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (PHP) 
 $count = 0;
if($rex2 == "4"){
$x = substr($line,0,17)  ;
if(($count % 6) < 3){
echo "<span style='color:red'>$x</span> <br> ";
}else{
echo "<span style='color:blue'>$x</span> <br> ";
}
$count +=1;
}
 // - - นึกว่าจะเอาไปใส่โค้ดสีเอง
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-12-16 16:07:12 | By :
                            noMerzy |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | Code (PHP) 
 <?php
$txt = "
4567.123
8901
4678.456
8802
4789
8888
4567
8901
4678
8802
4789
8888
4567
8901
4678
8802
4789
8888
4567
8901
4678
8802
4789
8888
4567
8901
4678
8802
4789
8888
";
$i=0; $j=0;
function callback_set_color($result_match){
	global $i, $j;
	//print_r($result_match);exit;
	$j=floor($i / 3) % 2; $i++;
	$color=array('red', 'blue');
	return "\n<font color='$color[$j]' >".$result_match[1].'</font>';
}
echo '<pre>',preg_replace_callback('/[\r\n]([4][^\r\n]+)/','callback_set_color', $txt),'</pre>';
 |  
              | 
 ประวัติการแก้ไข
 2015-12-16 18:09:26
 2015-12-17 20:40:30
 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2015-12-16 18:04:49 | By :
                            NewbiePHP |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |