Beginner Question

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
dddmx3
Forum Newbie
Posts: 16
Joined: Mon Sep 20, 2010 9:05 pm

Beginner Question

Post by dddmx3 »

I know this a real beginner question, but here I go:

I have this code:

Code: Select all

<?php phpfmg_checkboxes( 'field_4', "Rush my order (+$30)|I need a design (+$20)|Vectorize my artwork (+$25)" );?>
Problem is, when the php sees "$30" it thinks I'm about to write a new php code but really it's just text. How can I make the $ show up as text?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Beginner Question

Post by twinedev »

use single quotes so it does not try to parse variables
dddmx3
Forum Newbie
Posts: 16
Joined: Mon Sep 20, 2010 9:05 pm

Re: Beginner Question

Post by dddmx3 »

But it added the single quotes..

http://unitedtee.com/order
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Beginner Question

Post by califdon »

dddmx3 wrote:But it added the single quotes..r
I don't understand that, but in any case, use the escape character \ in front of the character you do not want interpreted.
dddmx3
Forum Newbie
Posts: 16
Joined: Mon Sep 20, 2010 9:05 pm

Re: Beginner Question

Post by dddmx3 »

You don't understand what?

Why it added the quotes?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Beginner Question

Post by califdon »

dddmx3 wrote:You don't understand what?

Why it added the quotes?
No, I don't understand what you are saying. What is "it" and what quotes are you referring to? Where are you seeing single quotes that "it" changed??

But to return to your original question, you don't seem to understand what double and single quotes are used for in PHP. Either can be used to enclose literal strings, but the difference is that within double quotes, the value (contents) of simple variables (like $xyz) are substituted for the name of the variable ($xyz). So if you want to use the character "$" as a literal (that is, to actually print a dollar sign), you must either use it within single quotes, so it won't be interpreted, or use the PHP escape character, the backslash (\), whose function is to "escape" being interpreted. A full explanation of how quoted strings behave can be found at: http://php.net/manual/en/language.types.string.php
dddmx3
Forum Newbie
Posts: 16
Joined: Mon Sep 20, 2010 9:05 pm

Re: Beginner Question

Post by dddmx3 »

Im talking about this.

This code:

Code: Select all

..."Rush my order (+$30)|I...

I added:

Code: Select all

..."Rush my order (+'$'30)|I...

And now it shows the $ symbol here but it also shows the single quotes.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Beginner Question

Post by califdon »

But you are doing that inside double quotes. If you're going to use single quotes, you have to put them around the outside of the string ('Rush my order (+$30)|I need a design (+$20)|Vectorize my artwork (+$25)'). Once you start a string (with single or double quotes), it will be interpreted as a string until the matching single or double quote is found.
dddmx3
Forum Newbie
Posts: 16
Joined: Mon Sep 20, 2010 9:05 pm

Re: Beginner Question

Post by dddmx3 »

Thanks, but that didn't work out too well either.

Code: Select all

<?php phpfmg_checkboxes( 'field_4', '"Rush my order (+$30)|I need a design (+$25)|Vectorize my artwork (+$20)"' );?>
Sorry, I don't know php.

Btw, does anybody know the answer to this?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Beginner Question

Post by califdon »

Get RID of those double quotes! Do it exactly as I showed you.
Post Reply