pdenlinger Posted January 18, 2007 Share Posted January 18, 2007 I'm having trouble with the following code; I get a Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' on line 14. Can you please tell me what the error is?Thank you.[code]<!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>Assigning values to variables</title></head><body> <h1>Assigning values to variables</h1> <?php echo "Setting number of apples to 1.<br>"; $apples=1; echo "Number of apples: ", $apples, "<br>" echo "Adding 3 more apples.<BR>"; $apples = $apples + 3; echo "Number of apples now: ", $apples, "<BR>"; ?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
zhahaman2001 Posted January 18, 2007 Share Posted January 18, 2007 [code]<?php echo "Setting number of apples to 1.<br>";$apples=1;at the end of the line below you need a ;echo "Number of apples: ", $apples, "<br>"echo "Adding 3 more apples.<BR>";$apples = $apples + 3;echo "Number of apples now: ", $apples, "<BR>";?>[/code]and instead of saying this echo "Number of apples now: ", $apples, "<BR>";you can say this echo "Number of apples now: $apples <BR>"; Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 18, 2007 Share Posted January 18, 2007 You are missing a semi-colon at the end of line 13. And you need to use a period to concatenate strings - not a comma Quote Link to comment Share on other sites More sharing options...
Nhoj Posted January 18, 2007 Share Posted January 18, 2007 [quote author=pdenlinger link=topic=123013.msg507989#msg507989 date=1169145496][code]<?php echo "Setting number of apples to 1.<br>";$apples=1;echo "Number of apples: ", $apples, "<br>";echo "Adding 3 more apples.<BR>";$apples = $apples + 3;echo "Number of apples now: ", $apples, "<BR>";?>[/code][/quote]If you're concatenating strings like that don't use double quotes, it wastes memory. It may not be a lot but in very very large scripts it can make a difference. Double quotes forces PHP to scan for variables within the quotes. Concatenating is nearly pointless when you use double quotes with it. (Not entirely, but nearly) Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 18, 2007 Share Posted January 18, 2007 Nhoj is right. A more effective way of writing all that is:[code]<?php echo 'Setting number of apples to 1.<br>';$apples=1;echo "Number of apples: $apples<br>Adding 3 more apples.<br>";$apples = $apples + 3;echo "Number of apples now: $apples<BR>";?>[/code]OR:[code]<?php echo 'Setting number of apples to 1.<br>';$apples=1;echo 'Number of apples: '.$apples.'<br>Adding 3 more apples.<br>';$apples = $apples + 3;echo 'Number of apples now: '.$apples.'<br>';?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.