Write a program to read a flat file “item.dat”, which contains details of 5 different items such as Item code, Item Name, unit sold, and Rate. Display the Bill in tabular format.

Write a program to read a flat file “item.dat”, which contains details of 5 different items

such as Item code, Item Name, unit sold, and Rate. Display the Bill in tabular format.

Program :

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
$file = fopen("item.dat", "r");
$sep = ",";
$con = file('item.dat');
echo "<table border='3px'>\n";
foreach ($con as $row)
{
echo "\t<tr>\n";
$cells = explode($sep, $row);
foreach ($cells as $cell)
{
echo sprintf("\t<td> %s </td>\n", $cell);
}
echo "\t</tr>\n";
}
echo "</table>\n";
foreach ($cells as $cell)
{
sprintf("\t<td> %s </td>\n", $cell);
}
fclose($file);
?>
</body>
</html>

<---item.dat file-->

Item Code,Item Name,Units Sold,Rate
101,Soap,2,20
103,Chair,6,300
102,Table,1,1000
11,Book,2,10
12,Door,1,100




Post a Comment

0 Comments