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

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

PHP include Template (PHP)

<?php include("inc_temp.php"); ?>
<!doctype html>
<html>
  <head>
    <title><?php echo($title); ?></title>
  <head>
  <body>
    <h2><?php echo($h2); ?></h2>
    <p><?php echo($par); ?></p>
    <p>This page calls a PHP convertTemp() function using a PHP include() function.</p>
    <?php
    echo("<p>\n");
    $far = ____;  
    convertTemp($far); 
    echo("</p>\n");
    ?> 
  </body>
</html>

PHP inc_temp.php Template (PHP)

<?php 
// initialize some page variables
$h2 = "put-welcome-heading-here";
$par = "put-welcome-paragraph-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");
} 
?>
Output