Back to DFS's Workshop Page
Back to Agenda Page
Again, your new script will generate the traditional "Hello, World!" greeting. However, this time you will introduce a pair of functions. Functions, even if not called more than once, can help make the main line of code more readable. Follow the simple steps below.
Get to the directory where you are storing your PHP code.
Create a new file called helloworld4.php so that it looks like the following code.
<?php
// PHP echoing "Hello World in HTML"
// Using functions
// helloworld4.php
function htmlheader ($t)
{
echo "<html>\n";
echo " <head>\n";
echo " <title>" . $t . "</title>\n";
echo " </head>\n";
echo " <body>\n";
}
function htmlfooter ()
{
echo " </body>\n";
echo "</html>\n";
}
$title = "Hello Using Functions";
htmlheader($title);
echo " <p>Hello, World!</p>\n";
htmlfooter();
?>
In your favorite web browser, type
http://localhost/~YOURID/test_php/helloworld4.phpwhere YOURID is the user ID you have on the system.