Let's Get Started with a PHP Input/Output Page!

  1. Open Notepad++
  2. Choose: File -> New
  3. Copy the PHP Input/Output Template (PHP) code (below)
  4. Paste that code into your new file
  5. Paste that code into your new file
  6. Change the put-title-of-this-page-here and put-welcome-heading-here strings.
  7. Click: File -> Save As
  8. Name your file: E:\public_html\io.php
  9. Change the Save as type: to: PHP Hypertext Preprocessor (*.php)
  10. Click: Save
  11. Save this file groceries.txt to your E:\public_html\ folder
  12. Visit your page (http://bscacad3.buffalostate.edu/io.php) in your favorite web browser
  13. Make any changes
  14. Save your changes

PHP Input/Output Template (PHP)

<?php
$title = "put-title-of-this-page-here"; 
$h2    = "put-heading-of-this-page-here"; 
$myArray = array("item-0", "item-1", "item-2", "item-3", "item-4");
?>
<html>
  <head>
    <title><?php echo($title); ?></title>
  <head>
  <body>
    <h2><?php echo($h2); ?></h2>
    <?php 
    $fh = fopen("groceries.txt", "r");
    // Parse each of comma-separated values.
    $thisLine = "<p>";
    while (list ($name, $cost, $unit) = fgetcsv($fh, 1024, ",")) {
      // trim spaces
      $name = trim($name);
      $cost = trim($cost);
      $unit = trim($unit);
      $thisLine .= "Don't forget to pickup <b>$name</b> (\$$cost per $unit)<br/>\n";
    }
    $thisLine .= "</p>\n";
    echo($thisLine);
    fclose($fh);
    ?>
  </body>
</html>
Output