Jump to content

Convert Variables To Plain Data


filoaman

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/269692-convert-variables-to-plain-data/
Share on other sites

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.

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

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

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.