2016-11-14 23 views
0

一個bbm.​​txt文件包含:PHP腳本逐行讀取TXT文件行,在約定格式進行排序,並計算統計

BBM, PHP, John Smith, 16/11/2016 

12345678 56 

34567822 67 

12324654 98 

你應該得到

File name: bbm.txt 

Module code: BBM 

Module Name: PHP 

Tutor: John Smith 

The award date: 16/11/2016 

12345678: 56 

34567822: 67 

12324654: 98 

我得到

BBM PHP John Smith 16/11/2016 

12345678 56 

34567822 67 

12324654 98 

請幫助。上述

function readLineByLine() { 
    if (file_exists('bbm.txt')){ 
     $tmaFileToOpen = fopen("bbm.txt", "r"); // open our bbm.txt file 
     if ($tmaFileToOpen) { // true if no errors occured 
      while(!feof($tmaFileToOpen)) { 
       // variable $result will display data in line by line 
       $result = fgets($tmaFileToOpen, 1024); 
       $split = explode(',', $result); 
       echo '<p>' . $split[0] . $split[1] . $split[2] . $split[3] . '</p>'; 
      } 
     } else { // if an error occured message will be displayed 
      echo '<p>There is an error openning file!</p>'; 
     } 
     fclose($tmaFileToOpen); // Close our bbm.txt file 
    } else { // if file doesn't exist message will be displayed 
     echo '<p>File requested not found!</p>'; 
    } 
} 
    echo readLineByLine(); 
+0

呃'回聲 '

模塊代碼:'。 $ split [0]。'
模塊名稱:'。 $ split [1]。'
導師'。 $ split [2]。'
獎勵日期:'。 $ split [3]。 '

';' – Manikiran

+0

它不起作用。輸出我的模塊代碼:BBM PHP約翰·史密斯16/11/2016 模塊代碼:12345678 56 模塊代碼:34567822 67 模塊代碼:一些逐字文本12324654 98 –

+0

更改格式。 – rlandster

回答

0

註釋是正確的:

'<p>Module Code:' . $split[0] .'<br>Module Name: '. $split[1] .'<br>Tutor'. $split[2] .'<br>The award date: '. $split[3] . '</p>'; 
相關問題