I'm trying to figure out how to write multiple variables to file using file_put_content.
My code:
<?php
$file = 'file.txt';
$data1 = "John Smith";
file_put_contents($file, $data1, FILE_APPEND | LOCK_EX);
?>
I have additional variables such as $data2, $data3 and $data4. I tried:
<?php
$file = 'file.txt';
$data1 = "John Smith";
$data2 = "Street Address";
$data3 = "Plumber";
$data3 = "Phone nuber";
file_put_contents($file, $data1, $data2, $data3, $data4,FILE_APPEND | LOCK_EX);
?>
but it's not working. I need to write all variables to file.txt so it looks like this:
John Smith Stret Address Plumber Phone Number
and each time when the script has been launched it should add new variables in a new line e.g:
John Smith Stret Address Plumber Phone Number
Mike Johnson Stret Address lectrician Phone Number
etc etc. Any ideas? :)