Building and Testing Pages
Follow this lesson in Ullman Chapter 1.
In your web root, create a folder named Backup. Back up the contents of your original web root to this folder.
Get the scripts used in our textbook:
http://www.dmcinsights.com/phpvqs2/scripts.phpUnzip them into your web root. Note that the folders are numbered to match the chapters.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″ />
<title>Sample XHTML Page </title>
</head>
<body>
<p>This is an XHTML page. Note that all tags must be closed, and all must be in lower case.</p>
</body>
</html>Save this file in your web root as index.htm, and view it through your browser.
What’s the difference between looking at the file as http://localhost/index.htm, and looking at it as c:/your_path/index.htm?
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″ />
<title>Sample PHP Page </title>
</head>
<body>
<p>This is static content.</p>
<p>
<?php
print (“This is dynamically created content.”);
?>
</p>
</body>
</html>Save it as template.php. What’s the difference between looking at the file as http://localhost/template.php, and looking at it as c:/your_path/template.php?
PHP opening and closing tags
<?php
print (“Hello, world!”);
?>
or
<?
print (“Hello, world!”);
?>
or
<%
print (“Hello, world!”);
%>
Semicolons
Use them else die;
Functions
The PHP Manual at
http://www.php.net/manual/en/index.php; search for “print.”See Ullman page 13 for a discussion of researching functions at PHP.net.
print(“Hello”);
View the page described on Ullman page 14, hello.php. (It’s in the 01 folder.)
Sending HTML to the browser
print “print() works fine without parentheses.”
print <<<END
This uses the “here document” syntax to output multiple lines with $variable interpolation. You can send these lines to a function like print(), or…
END;$var = <<<ends_here
…you can store the resulting string in a variable. Note that the heredoc terminator must appear on a line with just a semicolon following it, with NO extra whitespace!
ends_here;The ending string is simply a repeat of the starting string, in these examples “END” and “ends here” respectively.
The critical escape character: \
View the page described on Ullman pages 16-ff, hello2.php.
View the page described on Ullman pages 19-ff, hello3.php.
// or # , or /* */
View the page described on Ullman page 21, hello4.php.
<?php
phpinfo();
?>View the page test.php in the 01 folder.
Begin to construct your own “demo” website in your web root. It should demonstrate:
- XHTML page construction,
- PHP script tags and basic functions,
- Sending XHTML to the browser,
- Using escape and newline characters, and
- Using all three types of comments.
Review Chapter 1 of Ullman.