1

I am currently a Student, developing a Website for an Online Course Planning for Monash I am Stuck with a reading HTML files in my PHP code

I need to Upload a File (Unofficial Records of a Student) and once I Click Upload, the System MUST Scan the HTML file and read through the Tables from the first (of the academic Records to the Last one) where it says Incomplete and it must evaluate the Grade, if it is a P, C, D, HD, the System will automatically Cross that unit for the Student, if the Student has Failed, it will be a N and the System must automatically highlight the Unit in order to tell that the student needs to re do the Unit

when the Academic Record is saved from the official Monash website, it saves automatically as a HTML, so i have no way in changing that

(Note that it is a student who will download in future use, not programmers, so they might not know how to convert it)

Daryus Patel
  • 53
  • 1
  • 1
  • 3
  • Please ask a [mininal, complete and verifiable example](https://stackoverflow.com/help/mcve) – Alexandre Thyvador Aug 10 '17 at 09:56
  • Thanks for giving an overview about what you are doing. Do you have some particular question? – Pinke Helga Aug 10 '17 at 09:57
  • You need to provide a sample html file, your current php code that parses the file, and you need to describe where you got stuck along with any errors you receive. In its current format this question reads as if you wanted us to implement this html parsing feature from scratch for you. And this is not going to happen. – Shadow Aug 10 '17 at 09:58
  • i think you can use some string finding functions to build logic. Check PHP manual for that. – Star Aug 10 '17 at 10:01

3 Answers3

5

Like so - to read the file?

<?php
$text= file_get_contents('yourfile.htm');
echo $text;
?>

Once you have it grabbed, you can parse the HTML - see here: PHP Parse HTML code

Happysmithers
  • 733
  • 2
  • 8
  • 13
2

You can try this piece of code:

https://www.w3schools.com/php/func_string_money_format.asp

Here

<?php
$file = fopen("test.html","r");
echo fgets($file);
fclose($file);
?>

OR

Try:

readfile("/path/to/file");

OR

echo file_get_contents("/path/to/file");
1990rk4
  • 728
  • 11
  • 21
1

You could load the HTML into a DOMDocument and then iterate over the document nodes to extract the information.

A quick example from the top of my head (did not test it thought):

$document = new DOMDocument();
$document->loadHTMLFile("path-to-your-html-file.html");
$tableElement = $document->getElementById("your-table-id");
$allTableRows = $tableElement->getElementsByTagName("tr");
foreach($allTableRows as $tableRow) {
    $allTableCellsInThisRow = $tableRow->getElementsByTagName("td");
    $firstCell = $allTableCellsInThisRow->item(0);
    $secondCell = $allTableCellsInThisRow->item(1);
    // and so on ..
    // do your processing of table rows and data here
}

Links

Patrick
  • 133
  • 7