"$" in a string

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
jkashu
Forum Commoner
Posts: 45
Joined: Tue Jan 30, 2007 12:00 pm

"$" in a string

Post by jkashu »

I know this is something really easy that I'm forgetting, but how do I use a $ in a string without it being read as a variable?

<?

$var = "<? $page = gallery.php; ?>";

?>

The $var needs to be exactly what's in there without replacing the $page with something else.

Thanks!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Use single quotes
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Single quotes?
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

VladSun wrote:Single quotes?
Are you refering to my reply or the question?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Jcart PostPosted: Tue Aug 07, 2007 9:32 pm
VladSun PostPosted: Tue Aug 07, 2007 9:32 pm

:) Reply to the OP
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

VladSun wrote:Jcart PostPosted: Tue Aug 07, 2007 9:32 pm
VladSun PostPosted: Tue Aug 07, 2007 9:32 pm

:) Reply to the OP
Never know.. maybe you are quick on the draw? 8)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

It is obvious that you were quicker ... this time ;)
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Re: "$" in a string

Post by ghadacr »

Code: Select all

$page = "gallery.php";

$var =  '$page';
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You can also escape the character.

Code: Select all

echo "\$foo.";
Post Reply