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