Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1. <!--Author:
  2.     Date:
  3.     File:   Modify2.php
  4.     Purpose:Chapter 6 Exercise
  5.  
  6.     REQUIREMENT: Write a Web-based application consisting of a Web form
  7.     (Modify2.html) and a PHP progam (Modify2.php).
  8.  
  9.     Modify2.html includes a form that consists only of a Submit button
  10.     When the button is pressed, Modify2.php runs, opens the file
  11.     capitalInfo.txt which contans a list of four countries and capital
  12.     cities. The program reads and displays the country and capital city
  13.     from the first line.
  14.  
  15.     Modify Modify2.php so that it reads and displays all four countries and
  16.     capital cities in the capitalInfo.txt file.
  17.  
  18. -->
  19.  
  20. <html>
  21. <head>
  22.     <title>Modify2</title>
  23.     <link rel ="stylesheet" type="text/css" href="sample.css" >
  24. </head>
  25. <body>
  26.  
  27.     <h1>Modify2</h1>
  28.  
  29.     <?php
  30.         $capitalFile = fopen("capitalInfo.txt","r");   
  31.         $countryRecord1 = fgets($capitalFile);
  32.         $countryRecord2 = fgets($capitalFile);
  33.         $countryRecord3 = fgets($capitalFile);
  34.         $countryRecord4 = fgets($capitalFile);         
  35.         fclose($capitalFile);
  36.  
  37.         list ($country1, $capital1) = split(":", $countryRecord1);
  38.         list ($country2, $capital2) = split(":", $countryRecord2);
  39.         list ($country3, $capital3) = split(":", $countryRecord3);
  40.         list ($country4, $capital4) = split(":", $countryRecord4);
  41.  
  42.         print("<p>$capital1 is the capital city of $country1.</p>");
  43.         print("<p>$capital2 is the capital city of $country2.</p>");
  44.         print("<p>$capital3 is the capital city of $country3.</p>");
  45.         print("<p>$capital4 is the capital city of $country4.</p>");
  46.  
  47.     ?>
  48.  
  49. </body>
  50. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement