filoaman Posted October 19, 2012 Share Posted October 19, 2012 Hi friends I'm new with php and i want some help. I create a script and everything works OK while the script run on the server. Now what i want is store the code generated from the script on a plain file (txt or html) The problem is that when i try to store the data i get the php scripting on this file. Let's say that i have a variable called "$var" and the value of this variable right now is "12345" I'm looking for a way to store in my txt (or html) file the value of the variable (12345) and not the ($var) like i get right now. Any ideas? I search the net for a couple of hour but since i don't know exactly what i'm looking for is hard to find an answer. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/269692-convert-variables-to-plain-data/ Share on other sites More sharing options...
requinix Posted October 19, 2012 Share Posted October 19, 2012 (edited) You're using single quotes, aren't you? '$var' If you just have the variable in there then you don't need quotes at all. $var As for why it doesn't work: variables aren't interpreted in singly-quoted strings. However they are in doubly-quoted strings. "There's other stuff in this string besides $var" So if you don't have just the variable in there then use double quotes instead. Edited October 19, 2012 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/269692-convert-variables-to-plain-data/#findComment-1386399 Share on other sites More sharing options...
kicken Posted October 19, 2012 Share Posted October 19, 2012 Write the variable to a file with one of the file functions such as file_put_contents file_put_contents('myvar.txt', $var); Quote Link to comment https://forums.phpfreaks.com/topic/269692-convert-variables-to-plain-data/#findComment-1386400 Share on other sites More sharing options...
filoaman Posted October 19, 2012 Author Share Posted October 19, 2012 Thank you for your answers Actually the "$var" was just an example. Right now i try to store something more complex. Let's say that we have 4 different variables $var1, $var2, $var3 and $var4 and the values are 'test', 'foo', '55' and '12345'. When i use php i can echo this: echo "Today I make a ". $var1. " and then ". $var2 . " but finally i get only ". $var3 ." dollars instead of ." $var4; On screen i get this: Today I make a test and then foo but finally i get only 55 dollars instead of 12345 When i try to store it on a file i get the code (1st example). I like to store the 2nd example. Is that possible? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/269692-convert-variables-to-plain-data/#findComment-1386410 Share on other sites More sharing options...
kicken Posted October 19, 2012 Share Posted October 19, 2012 file_put_contents('yourfile.txt', "Today I make a ". $var1. " and then ". $var2 . " but finally i get only ". $var3 ." dollars instead of ". $var4); That will create a file named yourfile.txt which contains the text Today I make a test and then foo but finally i get only 55 dollars instead of 12345 Quote Link to comment https://forums.phpfreaks.com/topic/269692-convert-variables-to-plain-data/#findComment-1386454 Share on other sites More sharing options...
trq Posted October 19, 2012 Share Posted October 19, 2012 We can't really help much without seeing your code. Quote Link to comment https://forums.phpfreaks.com/topic/269692-convert-variables-to-plain-data/#findComment-1386491 Share on other sites More sharing options...
filoaman Posted October 20, 2012 Author Share Posted October 20, 2012 Finally the file_put_contents did the job, thank you kicken. I put all my code on a $data variable and then i store them using the file_put_contents function. Solved! Quote Link to comment https://forums.phpfreaks.com/topic/269692-convert-variables-to-plain-data/#findComment-1386570 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.