写的操作:
 
<?php
//定义一个字符串,准备写入order.txt文件
$outputstring=$date."\t".$tireqty." tires\t".$oilqty." oil\t".$sparkqty."spark plugs\t Price:".$totalmount."\t Your Address Is:".$address."\r\n";
//打开准备操作的文件并测试是否成功!
fp=fopen("order.txt","ab");
  if (!$fp) {
   echo '<p><strong>Your order could not be processed at this time,please try again later!</strong></p>';
   exit;
  }

 fwrite($fp,$outputstring,strlen($outputstring));
 fclose($fp);
 
 echo '<p>Order written</p>';
 ?>
 
读的操作:
<?php
$fp=fopen("order.txt","r");
if (!$fp) {
 echo "<p><strong>No orders pending.please try again later!</strong></p>";
 exit;
}

//feof函数用于测试是否到了文本的结束位置
//fgetc函数用于读取字符,指定长度
//fgetS函数用于读取一行字符
while (!feof($fp)) {
 $order=fgets($fp,999);
 echo $order.'<br>';
}
fclose($fp);
?>