Web Hosting Talk







View Full Version : $ question


MikeA
04-16-2003, 03:44 PM
Ok, I want to write something to a file, but don't want it to substitute a blank instead of what I want.

SO

$myvariable ="12345";

$messagetext = "<?PHP $test = $myvariable; ?>";

$fp = fopen($filename, "w") or die ("Couldn't open $filename");
fwrite($fp, $messagetext);


So what I would like to see in the file is:

<?PHP $test = 12345; ?>

JustinH
04-16-2003, 04:04 PM
$myvariable ="12345";

$messagetext = "<?PHP $test = " . $myvariable . "; ?>";

$fp = fopen($filename, "w") or die ("Couldn't open $filename");
fwrite($fp, $messagetext);


It should work the way you're doing it but try that.

Gamenati
04-16-2003, 04:27 PM
<?php
$myvariable ="12345";

$messagetext = "<?PHP $test = $myvariable; ?>";

$fp = fopen($filename, "w") or die ("Couldn't open $filename");
fwrite($fp, $messagetext);
?>

SynHost
04-16-2003, 04:29 PM
No.. that won't work.

If you want '$test' to be a literal, you need to escape the $.

Like this:

$messagetext = "<?PHP \$test = $myvariable; ?>";

MikeA
04-16-2003, 05:09 PM
Thanks all. SynHost's suggestion is what did it.