<!-- 12. PHP Program to read text file and display data using <table> tag. -->
<html>
<head>
<title>Reading a file using PHP</title>
</head>
<?php
// Turn off all error reporting
error_reporting(0);
?>
<body bgcolor=green text=white>
<?php
$fp = fopen('D:\\php.txt', 'r');
if( $fp == false )
{
echo ( "<h3>File not found!</h3>" );
exit();
}
$delimiter='#';
echo "<h3>Salary Details of Employees:</h3>";
print_r("<table border=3>");
print_r("<tr><th>EmpId</th><th>EmployeeName</th><th>Designation</th><th>Department</th>
<th>BasicSalary</th><th>Allowance</th><th>Deduction</th><th>GrossSalary</th><th>NetSalary</th></tr>");
while ( !feof($fp) )
{
$line = fgets($fp, 1024);
$data = str_getcsv($line, $delimiter);
$eid=$data[0];
$ename=$data[1];
$desig=$data[2];
$dept=$data[3];
$bsal=$data[4];
$all=$data[5];
$ded=$data[6];
$gsal=$bsal+$all;
$nsal=$gsal-$ded;
print_r("<tr>");
print_r("<td>".$eid. "</td>");
print_r("<td>".$ename. "</td>");
print_r("<td>".$desig. "</td>");
print_r("<td>".$dept. "</td>");
print_r("<td>".$bsal. "</td>");
print_r("<td>".$all. "</td>");
print_r("<td>".$ded. "</td>");
print_r("<td>".$gsal. "</td>");
print_r("<td>".$nsal. "</td>");
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
Search This Blog
Sunday, 23 January 2022
12. PHP Program to Read text file and Display data using TABLE tag.
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment