unexpected T_CHARACTER, expecting T_STRING or T_VARIABLE

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
Curtis782
Forum Commoner
Posts: 31
Joined: Tue Oct 25, 2005 3:34 pm

unexpected T_CHARACTER, expecting T_STRING or T_VARIABLE

Post by Curtis782 »

Newbie question:

When I use this code (line 494):

Code: Select all

echo "<option selected value='$myrow[\"partNo1\"]' class='style10'>&nbsp;</option>";
I get the following error:

Parse error: parse error, unexpected T_CHARACTER, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /path-to/modify.php on line 494

How can I appropriately mark up the $myrow["partNo1"] ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: unexpected T_CHARACTER, expecting T_STRING or T_VARIABLE

Post by feyd »

Code: Select all

echo "<option selected value='{$myrow["partNo1"]}' class='style10'>&nbsp;</option>";
User avatar
Moocat
Forum Contributor
Posts: 143
Joined: Wed Oct 12, 2005 9:28 am
Location: USA

Post by Moocat »

What about:

Code: Select all

echo "<option selected value=",$myrow['partNo1']," class='style10'>&nbsp;</option>";
?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Moocat wrote:What about:

Code: Select all

echo "<option selected value=",$myrow['partNo1']," class='style10'>&nbsp;</option>";
?
That will give a parse error. You use dots "." to concatenate, not commas.

It may not be any faster than just using the variable inside the double quotes however since the interpreter will still scan the double quoted string for variables to parse. Doing that, along with the use of single quotes has indeed been found to be faster however :D
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

d11wtq wrote:
Moocat wrote:What about:

Code: Select all

echo "<option selected value=",$myrow['partNo1']," class='style10'>&nbsp;</option>";
?
That will give a parse error. You use dots "." to concatenate, not commas.

It may not be any faster than just using the variable inside the double quotes however since the interpreter will still scan the double quoted string for variables to parse. Doing that, along with the use of single quotes has indeed been found to be faster however :D
Liar, liar, pants on fire.

Code: Select all

echo 'a', 'b', 'c';
^This works fine, since you can pass multiple parameters to echo. It's actually faster than concatenation, I've heard.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

*gulps* :oops:

It's OK every knows I'm still a n00b anyway :P
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

d11wtq wrote:*gulps* :oops:

It's OK every knows I'm still a n00b anyway :P
|'|`´| jU57 700 |`´|U(|-| 0|= 4 1337 |-|4><><0|2

*pant* *pant* 8O
Post Reply