Jump to content

[SOLVED] Read a file with variables and save in a new file with values...


kalevra

Recommended Posts

Hi guys,

 

I'm kind of stuck and althought it's probably a ridiculously simple problem I can't seem to get past it.

I'm trying to open and read the content of a text file which contains let's say this:

 

Hi my name is $firstName $lastName.

I like driving $vehicule.

EOF

 

My script goes like this:

<?

$firstName = "John";

$lastName ="Doe";

$vehicule ="cars";

 

$filename = "template.txt";

$fh = fopen($filename, "r") or exit("Unable to open template...");

 

$fileContent = fread($fh, filesize($filename));

 

fclose($fh);

 

 

$filename = "tmp".md5(time()).".txt";

$fh = fopen($filename, "w") or exit("Unable to create new file...");

 

fwrite($fh, $fileContent);

fclose($fh);

 

echo "File created successfully..."

?>

 

Now when opening the file created by this script it still reads:

Hi my name is $firstName $lastName.

I like driving $vehicule.

 

And I would like it to read:

Hi my name is John Doe.

I like driving cars.

 

 

Help, hint, anything anyone? :-\

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.