Let's Get Started with a PHP Input/Output Page!
- Open Notepad++
- Choose:
File -> New
- Copy the PHP Input/Output Template (PHP) code (below)
- Paste that code into your new file
- Paste that code into your new file
- Change the put-title-of-this-page-here and
put-welcome-heading-here strings.
- Click: File -> Save As
- Name your file: \www\io.php
- Change the
Save as type:
to: PHP Hypertext Preprocessor (*.php)
- Click: Save
- Save this file groceries.txt to your \www\ folder
- Visit your page (http://buffalo.edu/io.php) in your favorite web browser
- Make any changes
- 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