Forum Moderators: coopster

Message Too Old, No Replies

Passing Variable Value to File

Instead of the variable

         

garyr_h

2:16 am on Jun 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have been working on this script for a while, but I can't seem to figure out how to pass the variable content to the file instead of the variable. For instance:


<?
//
// Start file creation
//

$fp = fopen($user . '.php', 'w');

$content ='<? $layer03_id = imageCreateFromgif($layer03);
$layer02_id = imageCreateFromgif($layer02);

// get layer03 size
$layer03_X = ImageSX($layer03_id);
$layer03_Y = ImageSY($layer03_id);

// get layer02 size
$layer02_X = ImageSX($layer02_id);
$layer02_Y = ImageSY($layer02_id);

// use a background image
$layer01image = imageCreateFromgif($layer01);

// merge the two together with alphablending on!
ImageAlphaBlending($layer01image, true);
imagecopy($layer01image, $layer03_id, 0, 0, 0, 0, $layer03_X, $layer03_Y);

// merge third file
ImageAlphaBlending($layer01image, true);
imagecopy($layer01image, $layer02_id, 0, 0, 0, 0, $layer02_X, $layer02_Y);
header("Content-type: image/gif"); Imagegif($layer01image);

// destroy the memory
ImageDestroy($layer01image);
ImageDestroy($layer03_id);
ImageDestroy($layer02_id);?>';

fwrite($fp, $content);
fclose($fp);
?>

Sends it exactly this way. I want it to use the value of each variable instead of sending the variable itself. ie; it sends the word $layer01 instead of sending moo.gif

I have tried taking out the <? and?> within $content but there is still no luck. All the variables are defined also.

Any help? or am I as bad at describing this as I think?

MattAU

5:21 am on Jun 13, 2005 (gmt 0)

10+ Year Member



If a $variable is inside ' (single quotes), it won't be parsed and $variable will become part of the string. If it's inside " (double quotes) or not in quotes at all, it will be parsed and the value will become a part of the string.

eg.
$test = 'hello';
echo '$test'; //outputs $test
echo "$test"; //outputs hello
echo $test; //outputs hello

So you'll probably need to concatenate some strings and do something like:

$content = '<? $layer03_id = imageCreateFromgif(' . $layer03 . ');';

which will output to the file:

<? $layer03_id = imageCreateFromgif(thisVarValue);

Hope this helps :)

garyr_h

3:45 pm on Jun 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks :D That's exactly what I needed!