Newbee question

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply

Wed Oct 09, 2002 6:37 am


Can anybody point me in the right direction Im very new to php and any help would be appreciated

Whats wrong with this snippt of code??

echo '<img src="catalog/affiliates/$_SERVER['SERVER_NAME']/oscommerce.gif">' ;


I get the following error

unexpected T_STRING, expecting ',' or ';'

Thanks in advance

New php-forum User
New php-forum User
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada

Wed Oct 09, 2002 6:48 am

Your string has single quotes at the ends AND you have single quotes inside your string... thats bad :)

Try this...

Code: Select all


echo '<img src="catalog/affiliates/'.$_SERVER['SERVER_NAME'].'/oscommerce.gif">' ;


I'm pretty sure that'll fix your problem :D


Wed Oct 09, 2002 2:16 pm

The main difference between using single quotes (') and double quotes(") is that single quotes will quote a string exacty:
print 'The variable value is $value'; will output The variable value is $value
Double quotes will parse the string for variables and replace them, therefore (assuming $value = 50) using double quotes for the same line will output The variable value is 50

You also can't use the same style quote within your string (otherwise the parser wouldn't know where your string ended). If you have to use the same quote, escape it with a backslash first so it's not taken literally (or use double quotes if you're using single - I personally find using double quotes far easier)
eg print 'That's Amazing' - Wrong
print 'That\'s Amazing' - Correct
print "That's Amazing" - Even better

You also cannot use an array variable within a string, unless you either access it directly in PHP (ie close the string, concatenate the variable and reopen the string) or enclose it within curly braces
eg - print "The value is $_SESSION['value']"; - Wrong
print "The value is {$_SESSION['value']}"; - OK
print "The value is ".$_SESSION['value']; - Much better


Thu Oct 10, 2002 10:37 pm

Great, that really helps.
Thanks for the advice

Post Reply