Jump to content

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.

Edited by requinix

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.