PHP Parse error: syntax error, unexpected T_LNUMBER Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tbrown
Forum Newbie
Posts: 2
Joined: Sun Jun 04, 2006 4:34 pm

PHP Parse error: syntax error, unexpected T_LNUMBER Error

Post by tbrown »

Hello my name is Tom. I am new to PHP. I bought the "PHP5, Apache, MYSQL" book by Liz Naramore(and others). I have been doing well - but hit a snag. I am copying vebatim from the book (with the exception of using " instead of "HEREDOC" to close a group of code). This is the error I get:

Parse error: syntax error, unexpected T_LNUMBER in C:\Program Files\thepath\movie_details.php on line 107

and this is the code (a little b4 and after the error location) with lines 107 highlighted :


$movie_health = calculate_differences($movie_takings, $movie_cost);
$page_start =
"<html>
<head>
<title>Details and Reviews for: $movie_name</title>
</head>
<body>
";

$movie_details =
"<table width="70%" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<th colspan="6"><u><h2>$movie_name: Details</h2></u></th>
</tr>
$movie_table_headings
<tr>
<td width="33%" align="center">$movie_name</td>
<td align="center">$movie_year</td>
<td align="center">$director</td>
<td align="center">$leadactor</td>
<td align="center">$movie_running_time</td>
<td align="center">$movie_health</td>
</tr>
</table>
<br>
<br>
";


Now, i have rechecked for typo errors 3 times - could it have to do with using " instead of HEREDOC? The tutorail scripts have been woking fine till this. Thanks for any help, it is greatly appreciated.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

If you want to use double quotes inside of a double quoted section of text you must escape the nested double quotes with a preceeding backslash. A better way to group text with nested double quotes is to enclose it in single quotes, in this case, you will not have to escape the double quotes, although you will not be able to handle variables properly.

For example:

Code: Select all

echo "he said "yo" and then left";
This is what you have done, the section of text is ended before 'yo', giving an error.

Code: Select all

echo "he said \"yo\" and then left";
This is what you should do to fix the problem.

Code: Select all

echo 'he said "yo" and then left';
This is what you could do in a similar situation to avoid escaping characters.

Sadly, that's not the end of it.

Code: Select all

$name = 'dave';
echo 'John looked at $name and smiled.'; //Will print exactly what's in the quotes.
echo "John looked at $name and smiled."; //Will print John looked at dave and smiled.
echo 'John looked at ' . $name . ' and smiled.'; //Is how to work-around it.
Post Reply