You need to write a program that opens a text file, reads data and displays information in the browser.
Create a text file.
The source text file has the following format:21.01.01 / 12:00 / подготовка к сессии22.01.01 / 14:00 / сдача сессии23.01.01 / 15:00 / гуляй...Open the file, read the data.
The data should be displayed in a browser in the form of a table.When writing a program you need to consider the following exceptions:
- text file may not be;
- There may be errors when composing a text file.
================================================= ================
So everything is done except the last point.
<html> <head> <meta charset="UTF-8"> <title>test (PHP)</title> </head> <body> <?php $fname = '1.txt'; $delim = '/'; if (file_exists($fname) && is_readable($fname)) { $file = file($fname); echo "<table border = '1'> <tr> <th>Дата:</th> <th>Время:</th> <th>Событие:</th> </tr>"; foreach ($file as $item) { $newItem = explode($delim, $item); echo "<tr> <td>$newItem[0]</td> <td>$newItem[1]</td> <td>$newItem[2]</td> </tr>"; } echo '</table>'; } else { echo "File not found!"; } ?> </body> </html> How to check file format errors.
That is, if there is an extra "/" in the file or it is not at all, the program should show an error!