⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 output.php

📁 这是php专业项目实例开发一书的源代码,希望对大家有所帮助!
💻 PHP
字号:
<html>
<head>
<title>Display Output </title>
</head>

<body>
<br><br><br>
<center>
<?php

//----create file if doesnt exist and open in write mode------
   if (!(file_exists("booboo.dat")))
   {
    $fp = fopen("booboo.dat","w+");
   }
   else   {//-----------otherwise if file exists then open in append mode-------       $fp = fopen("booboo.dat","a");
   }     if (empty($fiction)){ $fiction = "0";}if (empty($action)){ $action = "0";}if (empty($horror)){ $horror = "0";}if (empty($thrillers)){ $thrillers = "0";}if (empty($comedy)){ $comedy = "0";}for($i=0;$i<5;$i++){if (empty($hobbies[$i])){ $hobbies[$i] = "0";}}
//---------format the all the info for a record in 1 line seperated by spaces-------
  $dataformat="A20A200A50A6A10A2A4A1A1A1A1A1A20A20A20A20A20A20A1";
   $line = pack($dataformat,$name,$address,$email,$gender,$birth_month,$birth_day,$birth_year,$fiction,$action,$horror,$thrillers,$comedy,$hobbies[0],$hobbies[1],$hobbies[2],$hobbies[3],$hobbies[4],$hobbies[5],"\n");
  echo $line,"<br>",strlen($line);  
//----write to file
  $result = fputs($fp,$line) or die("Data could not be written to the file.");
  fclose($fp);?>

<h2> The following information was entered and accepted.</h2>
</center>
<table width="300" border="1" bgcolor="#EEFFEE" align="center" cellspacing=2 cellpadding=5>
  <tr> 
    <td>Full Name </td>
    <td>
      <h3><?php echo $name; ?> </h3>
    </td>
  </tr>

  <tr> 
    <td>e-mail </td>
    <td>
      <h3><?php echo $email; ?> </h3>
    </td>
  </tr>
  <tr> 
    <td>Address </td>
    <td>
      <h3><?php echo $address; ?> </h3>
    </td>
  </tr>
  <tr> 
    <td>Gender </td>
    <td>
      <h3><?php echo $gender; ?> </h3>
    </td>
  </tr>
  <tr> 
    <td>Date of Birth</td>
    <td>
     <h3> <?php echo $birth_month," ",$birth_day,"  ",$birth_year; ?> </h3>
    </td>
  </tr>
  <tr>
    <td>
       You prefer these books 
    </td>
    <td>
    <h3>
<?php
 if ($fiction) 
 { 
  echo "fiction <br>";
 }
 if ($action) 
 { 
  echo "action <br>";
 }
 if ($thrillers) 
 {
  echo "thrillers <br>";
 }
 if ($horror) 
 { 
  echo "horror <br>";
 }
 if ($comedy) 
 {
  echo "comedy ";
 }
?>
</h3>
</td>
  </tr>
  <tr>  <td>   Your hobbies are :   </td>   <td>   <?php    for ($i=0;$i<6;$i++)   {    if(!($hobbies[$i]=="0"))    {      echo "<h3>",$hobbies[$i],"</h3><br>";    }   }   ?>   </td></table>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -