Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Table</title>
- </head>
- <body>
- <h1>File info</h1>
- <?php
- $currentRow = "name: Ivan salary:5000 town:Sofia age:20 ";
- $splitCurrentRow = explode(" ", $currentRow);
- /* $name = explode (":", $splitCurrentRow[0][1];
- $salary = explode (":", $splitCurrentRow[1][1];
- $towwn = explode (":", $splitCurrentRow[2][1];
- $age = explode (":", $splitCurrentRow[3][1];
- */
- /*echo"<pre>";
- echo var_dump($name);
- echo var_dump($salary);
- echo var_dump($town);
- echo var_dump($age);
- echo"<pre>";
- */
- $myfile = fopen("namesInfo.txt", "r") or die("Unable to open file!");
- $table = "<table border = \"1px\">";
- $table .= "<thread>";
- $table .= "<tr>";
- $table .= "<th>Name</th>";
- $table .= "<th>Salary</th>";
- $table .= "<th>Town</th>";
- $table .= "<th>Age</th>";
- $table .= "</tr>";
- $table .= "</thread>";
- $table .= "<tbody>"
- $countName = 0;
- $sumSalary = 0;
- $sumAge = 0;
- $towns = array();
- while(!feof($myfile)) {
- $currentRow = fgets($myfile);
- $splitCurrentRow = explode("",$currentRow);
- if(count($splitCurrentRow) != 1){
- $name = explode(":", $splitCurrentRow[0])[1];
- $salary = explode(":", $splitCurrentRow[1])[1];
- $town = explode(":", $splitCurrentRow[2])[1];
- $age = explode(":", $splitCurrentRow[3])[1];
- $table .= "<tr>";
- $table .= "<td>". $name. "</td>";
- $table .= "<td>". $salary. "</td>";
- $table .= "<td>". $town. "</td>";
- $table .= "<td>". $age. "</td>";
- $table .= "</tr>";
- $countName++;
- $sumSalary += $salary;
- $sumAge += $age;
- $towns[] = $town;
- }
- }
- $averageAges = round($sumAges / $countName);
- $table .= "</tbody>";
- $table .= "<tfoot>";
- $table .= "<tr>";
- $table .= "<td style =\"color:red\">Count name: " . $countName . "</td>";
- $table .= "<td style =\"color:red\">Sum salary: " . $sumSalary . "</td>";
- $table .= "<td style =\"color:red\"> " . $towns . "</td>";
- $table .= "<td style =\"color:red\"> " . $averageAges . "</td>";
- $table .= "</tr>";
- $table .= "</tfoot>";
- $table .= "</table>";
- echo $table;
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement