Let's Get Started with a PHP function() Page!

  1. Open Notepad++
  2. Choose: File -> New
  3. Copy the PHP function() Template (PHP) code (below)
  4. Paste that code into your new file
  5. Change the put-welcome-heading-here, and put-welcome-paragraph here strings.
  6. Change the put-title-of-this-page-here to:
    function
  7. Change the ___ in this line:
    $far = ____; to some fahrenheit temperature
    function
  8. Click: File -> Save As
  9. Name your file: /public_html/function.php
  10. Change the Save as type: to: PHP Hypertext Preprocessor (*.php)
  11. Click: Save
  12. Visit your page (http://bscacad3.buffalostate.edu/function.php) in your favorite web browser
  13. Make any changes
  14. Save your changes

PHP function() Template (PHP)

<?php 
// initialize some page variables
$h2 = "put-welcome-heading-here";
$title = "put-title-of-this-page-here";

// define the function
function convertTemp($far) {
  $cen = ($far -32) * 5 / 9;
  echo("$far degrees f converts to $cen degrees c\n");
}
?>
<!doctype html>
<html>
  <head>
    <title><?php echo($title); ?></title>
  <head>
  <body>
    <?php 
    echo("<h2>$h2</h2>\n"); 
    echo("<p>This page calls a PHP convertTemp() function.</p>\n");
    echo("<p>");
    $far = ____;  
    convertTemp($far); 
    echo("</p>\n");
    ?>
  </body>
</html>
Output