Page 1 of 1

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

Posted: Sat Mar 15, 2008 7:17 pm
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?

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

Posted: Sat Mar 15, 2008 7:25 pm
by bertfour

Code: Select all

$stringData = "echo \"\$footerhere\"; \n";
I think...

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

Posted: Sat Mar 15, 2008 9:33 pm
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
?>