How to write $ and other symbols to a file in php

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
pyromaster114
Forum Newbie
Posts: 19
Joined: Fri Mar 14, 2008 8:12 pm

How to write $ and other symbols to a file in php

Post by pyromaster114 »

Okay so I have a script that needs to write a few things (okay like 100 things...) to a file.
It works perfectly, except for ONE thing.
Every time I tell it to write something like $hello... it substitutes the value of $hello (which since it's not assigned is blank).

My code:

Code: Select all

$stringData = "echo \"$footerhere\"; \n";
fwrite($fh, $stringData);
What I want to see in the file is:
echo "$footerhere";

what I see is:
echo "";

How do I make it write the var. name?
bertfour
Forum Commoner
Posts: 45
Joined: Fri Mar 07, 2008 7:33 am

Re: How to write $ and other symbols to a file in php

Post by bertfour »

Code: Select all

$stringData = "echo \"\$footerhere\"; \n";
I think...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: How to write $ and other symbols to a file in php

Post by RobertGonzalez »

Single quotes. They are sting literals.

A quick test...

Code: Select all

<?php
$hello = 'Hi there';
 
echo "$hello"; // in real life you would leave off the quotes to echo the variable
// Output: Hi there
 
echo '$hello';
// Output: $hello
?>
Post Reply