Welcome to Dream.In.Code
Become a PHP Expert!

Join 136,940 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,866 people online right now. Registration is fast and FREE... Join Now!




How do I print a variable name?

 
Reply to this topicStart new topic

How do I print a variable name?

dls76
10 Mar, 2008 - 03:51 PM
Post #1

New D.I.C Head
*

Joined: 15 Feb, 2008
Posts: 18

I know this is a crazy question! We are having to make a test and then figure the grade and display the questions that were missed. I have it all working but it isn't displaying one of the questions right when it is missed. I haven't been able to figure out how to get it to display correctly. I have tried double quotes and single quotes. The original question is: The statement "5 = $variable" will ---and then the user choses an answer.

Thank you for your help!

CODE

echo
    "3. The statement '5 = $variable' will
    <br />
     A. compare $variable to 5
     <br />
     B. set $variable to 5
     <br />
     <b>C. result in an error</b>
     <br />
     D. none of the above
     <br />
    <br />";


User is offlineProfile CardPM
+Quote Post

spearfish
RE: How Do I Print A Variable Name?
10 Mar, 2008 - 04:59 PM
Post #2

Monkey in Training
Group Icon

Joined: 10 Mar, 2008
Posts: 746



Thanked: 2 times
Dream Kudos: 225
My Contributions
QUOTE(dls76 @ 10 Mar, 2008 - 04:51 PM) *

CODE

echo
    "3. The statement '5 = $variable' will



That's your problem right there. Are you getting a parse error? Because it's likely that PHP is trying to:
CODE

echo $variable'


Your question was ambiguous as to what you are trying to do. If you want it to echo the variable, you need to separate it from the apostrophe like this:
CODE

echo "{$variable}'"


Remember variables in double quotes will expand, but not if PHP is looking for the wrong variable!

Another thing you might be trying to do is have it literally type "$variable", in which case you need to escape the dollar sign like this:
CODE

echo "\$variable"


Hope I helped, and feel free to correct me.
User is offlineProfile CardPM
+Quote Post

dls76
RE: How Do I Print A Variable Name?
10 Mar, 2008 - 05:19 PM
Post #3

New D.I.C Head
*

Joined: 15 Feb, 2008
Posts: 18

I wanted it to literally print $variable. That helped, I got it to work. Thank you so much!



QUOTE(spearfish @ 10 Mar, 2008 - 05:59 PM) *

QUOTE(dls76 @ 10 Mar, 2008 - 04:51 PM) *

CODE

echo
    "3. The statement '5 = $variable' will



That's your problem right there. Are you getting a parse error? Because it's likely that PHP is trying to:
CODE

echo $variable'


Your question was ambiguous as to what you are trying to do. If you want it to echo the variable, you need to separate it from the apostrophe like this:
CODE

echo "{$variable}'"


Remember variables in double quotes will expand, but not if PHP is looking for the wrong variable!

Another thing you might be trying to do is have it literally type "$variable", in which case you need to escape the dollar sign like this:
CODE

echo "\$variable"


Hope I helped, and feel free to correct me.


User is offlineProfile CardPM
+Quote Post

spearfish
RE: How Do I Print A Variable Name?
10 Mar, 2008 - 05:24 PM
Post #4

Monkey in Training
Group Icon

Joined: 10 Mar, 2008
Posts: 746



Thanked: 2 times
Dream Kudos: 225
My Contributions
Glad I could help you out pirate.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 10:54PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month