Data is written to a text file and read out to the browser's PHP code

Source: Internet
Author: User
Tags flock

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>gwbjx123</title>
<link rel= "stylesheet" style type= "Text/css" href= "Style/basic.css"/>
<body>
<form action= "eg1.php" method= "POST" >
<table cellspacing= "2" cellpadding= "0" border= "0" >
<tr>
<th width= "bgcolor=" "Red" >Item</th>
<th width= "$" bgcolor= "Red" >Quantity</th>
</tr>
<tr>
&LT;TD width= "" bgcolor= "green" >Tires</td>
<td><input type= "text" name= "Tires" size= "5"/></td>
</tr>
<tr>
&LT;TD width= "" bgcolor= "green" >oil</td>
<td><input type= "text" name= "Oil" size= "5"/></td>
</tr>
<tr>
&LT;TD width= "bgcolor=" "Green" >spark plugs</td>
<td><input type= "text" Name= "Spark" size= "5"/></td>
</tr>
<tr>
&LT;TD width= "" bgcolor= "green" >Address</td>
<td><input type= "text" name= "Address" size= "/></td>"
</tr>
<tr>
&LT;TD colspan= "2" align= "center" ><input type= "Submit" value= "Submit"/></td>

</tr>
</table>
</form>
</body>


Here is the PHP file: eg1.php

<?php
$tires = $_post[' tires ');
$oil = $_post[' oil '];
$spark = $_post[' spark ');
$address = $_post[' address '];
$outputstring = $tires. " \ t ". $oil." \ t ". $spark." \ t "
. $address. " \ n ";
echo "File stored in ......<br/>";
$fp = fopen ("Egtext.txt", "AB");//a is an additional
Flock ($FP, LOCK_EX);
if ($fp) {
Fwrite ($fp, $outputstring, strlen ($outputstring));
}
Flock ($FP, lock_un);
Fclose ($FP);
echo "file is stored. "
?>

<body>

<?
$fp = fopen ("Egtext.txt", "RB");
Flock ($FP, LOCK_EX);
while (!feof ($fp)) {
$order = fgets ($fp, 999);
echo $order. " <br/> ";
}
Flock ($FP, lock_un);
Fclose ($FP);
?>
</body>

<?
$orders = File ("Egtext.txt");//file files are loaded into a text file with 1 elements (records) per action in the file.
$count _orders = count ($orders);//Statistics total number of records.
if ($count _orders==0) {
echo "<p> No orders pending</p>";
}

echo "<table border=\" 1\ ">";

echo "<tr><th bgcolor=\" #ccccff \ ">Tires</th>
<th bgcolor=\ "#ccccff \" >oil</th>
<th bgcolor=\ "#ccccff \" >spark</th>
<th bgcolor=\ "#ccccff \" >address</th>

</tr> ";
for ($i =0; $i < $count _orders; $i + +) {
$line = explode ("\ t", $orders [$i]);//\t double quotation marks must be double quotes. Otherwise the data shows an error

$line [0]=intval ($line [0]); Probably because "\ t" is split in code when adding data
$line [1]=intval ($line [1]);
$line [2]=intval ($line [2]);
echo "<tr><td align=\" right\ ">". $line [0]. " </td>
&LT;TD align=\ "right\" > ". $line [1]." </td>
&LT;TD align=\ "right\" > ". $line [2]." </td>
&LT;TD align=\ "right\" > ". $line [3]." </td>
</tr> ";


}
echo "</table>";
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.