From this txt file you need to take data

DT1617T2, Problem Solving for Programming, Gordon MacIntyre, 04/08/2016

12345678, 56

34567822, 67

12324654, 98

It should work

File name: ppGM.txt

Module Code: DT1617T2

Module Title: Problem Solving for Programming

Tutor: Gordon MacIntyre

Marked date: 08/04/2016

12345678: 56

34567822: 67

12324654: 98

And I get

DT1617T2 Problem Solving for Programming Gordon MacIntyre 04/08/2016

12345678 56

34567822 67

12324654 98

I need help, I write php for the first time.

function readLineByLine () { if (file_exists('ppGM.txt')){ $tmaFileToOpen = fopen("ppGM.txt", "r"); // open our ppGM.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 ppGM.txt file } else { // if file doesn't exist message will be displayed echo '<p>File requested not found!</p>'; } } echo readLineByLine(); 

    1 answer 1

    Try this code:

     <?php function readLineByLine () { $file_str = 'php.txt'; if (file_exists($file_str)){ $file = file($file_str); $named = explode(',', $file[0]); print 'File name: ' . basename($file_str) . '<br>'; print 'Module Code: ' . $named[0] . '<br>'; print 'Module Title: ' . $named[1] . '<br>'; print 'Tutor: ' . $named[2] . '<br>'; print 'Marked date: ' . $named[3] . '<br>'; $len = count($file); for ($i=1; $i < $len; $i++) { $str = explode(',', $file[$i]); print $str[0] . ': ' . $str[1] . '<br>'; } } } readLineByLine(); 

    Exhaust

     File name: php.txt Module Code: DT1617T2 Module Title: Problem Solving for Programming Tutor: Gordon MacIntyre Marked date: 08/04/2016 12345678: 56 34567822: 67 12324654: 98