Take a simple XHTML page and save it as prologtest.php, with the code below:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>An XHTML 1.0 Strict standard template</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>
<body>
</body>
</html>As before, upload this page to your server and use your browser to look at it in that location.
Depending on how your server is set up (error messages shown or repressed) you will see either nothing at all on the page, or an error line similar to the following:
Parse error: syntax error, unexpected T_STRING in
/f2/demosthenes/public/test.php on line 1
This demonstrates two important points:
When PHP doesn't work (almost always due to an error in your code) it really doesn't work: the page stops, and you get an error message, or nothing at all.
The
echostatement prints information to the page: that information could be a text string, as we have above, HTML, a variable, or a combination of all three. Anything other than a variable must be enclosed inside quotes; either single quotes ('') or double quotes("").
So what's the problem with our page?
The PHP opening tag is usually <?php ..., but it may also be shortcut to <? .... This latter, optional format for the opening tag confuses the PHP parser, which attempts to interpret our opening XML prolog as PHP. There are several possible solutions to this:
Drop the XML prolog. Doing so sacrifices a little flexibility, keeps your page valid, and is probably the quickest solution.
Set the PHP parser to only accept the long form of the opening PHP tag and ignore the short version.
Use PHP to echo the XML prolog. Replace the first line of the page with the following code (note the uses of single quotes):
<?php echo '<?xml version="1.0" encoding="utf-8"?>' ?>
Choose the option that appeals to you, make the appropriate change, save and upload the page, and view it again.
Pro CSS3 Animation, Apress, 2013