BYO Database Driven Web Site P 49

I tried the today.php program on page 49 and I get the following.

Parse error: syntax error, unexpected T_ECHO in /Library/WebServer/Documents/today.php on line 13

I’ve verified it against the code archive and if I put a phpinfo(); on the line before I get the date printed correctly after the info. I’m confused.

HP 5.2.12 (cli) (built: Feb 9 2010 00:34:23)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
Macintosh-2:Documents sski$ php -v
PHP 5.2.12 (cli) (built: Feb 9 2010 00:34:23)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies

OS X 10.5.8

Suggestions? Comments? Flames?

Yeah, once I put the example code and the stuff I typed in side by side on a bigger monitor, I was able to see the typo.

Should have done that earlier, but I got sidetracked by the phpinfo thing. Thanks for the help and comments.

Once I had a bug that I spent about a hour trying to solve. One of my cats had stepped on the keyboard’s backtick key (upper left corner) and no matter how often I looked I didn’t see the ` (well, until the last time) :eye:

But I do put more effort into keeping my monitor clean now :wink:

A good tip is in whatever program your writing the code in, use a font that has fixed character widths eg Lucida Console, Courier, etc. It makes it a bit easier to spot stray things like ` lurking in code, also try not to use too small a font size.

Another thing that will help (if the program that your using allows it) is syntax highlighting, things like built-in function names, constants, comments etc each get shown in a different font colour.

No comments and no flames… If find it strange that the page works if you use the phpinfo() function but no if you remove it. I know that you verified, but have you tried to use the code archive directly? Does that file work? Then, it is obvious that you mistyped something. It is the only thing that make sense… maybe a semi-colon ([noparse];[/noparse]) at the end of the instruction?

Hi stevenski, welcome to the forums,

I admit I’m confused too. There isn’t much PHP in that file for it to go wrong.

<!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>Today&rsquo;s Date</title>
		<meta http-equiv="content-type"
				content="text/html; charset=utf-8"/>
	</head>
	<body>
		<p>Today&rsquo;s date (according to this web server) is
			<?php

			echo date('l, F dS Y.');

			?>
		</p>
	</body>
</html>

Are you certain there isn’t an extraneous character between the <?php and the echo somewhere?