kalevra Posted July 13, 2008 Share Posted July 13, 2008 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? :-\ Link to comment https://forums.phpfreaks.com/topic/114480-solved-read-a-file-with-variables-and-save-in-a-new-file-with-values/ Share on other sites More sharing options...
rarebit Posted July 13, 2008 Share Posted July 13, 2008 Because your not including the file, the variables won't actually be treat like variables, so you'll need to use say, str_replace or preg_replace Link to comment https://forums.phpfreaks.com/topic/114480-solved-read-a-file-with-variables-and-save-in-a-new-file-with-values/#findComment-588657 Share on other sites More sharing options...
kalevra Posted July 13, 2008 Author Share Posted July 13, 2008 Lol, I knew this couldn't be too hard. Works fine, Thank a lot. Link to comment https://forums.phpfreaks.com/topic/114480-solved-read-a-file-with-variables-and-save-in-a-new-file-with-values/#findComment-588662 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.