-6

I want to create a .txt file with the following: $country = "china"; $valuta = "dollar";

And than I want to create a .php file with some text like: This is $country where they use $valuta

How do I achieve this in 2 different files

Maybe include once or require once

Strtz
  • 9
  • 3
  • 1
    Have you tried `include` or `require`? Did it work? If not, did you get an error? Blank page? Does it have to be a `.txt` file? – brombeer Dec 04 '22 at 13:01
  • 1
    This sees like a XY problem, what are you trying to achieve that a .PHP file needs to pull data (PHP variables) from a .txt file? – Buttered_Toast Dec 04 '22 at 13:07
  • Yes buttered_toast, i want a php file that pulls data (php variables) from a .txt file – Strtz Dec 04 '22 at 13:47
  • But why? what are you trying to do that this is the solution you came up with? – Buttered_Toast Dec 04 '22 at 13:47
  • What's a better solution ? I want to create many variables so i want to put it in external file – Strtz Dec 04 '22 at 13:48
  • But why place them in a `.txt` file? Why not use a `.php` file? (`.txt` files won't be parsed by PHP (unless you told your server to do so) – brombeer Dec 04 '22 at 14:08
  • Ok, but how do I achieve this ? My variables in external php file – Strtz Dec 04 '22 at 14:34

1 Answers1

0

why not just store in .env file?

technically you could create a .inc file with opening <?php and declare your variable inside. Then include this file in your script.

if you insist on using .txt file, serialize your value inside the txt file, then inside your php script use file_get_contents() php function and unserialize the result.