• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

PHP - Sending information to a file.

Jonny

Golden Member
Good day everyone, I'm doing some PHP and wondering how I can send information to a text file. I really don't have any idea how to do this right now, so any input would be excellent!

Thanks!
 
im not sure myself,

but from what i understad, there isnt really way. u need an mySQL server (which is a database) so that when the information is input it saves it in the database.

if i am wrong please can someone put me wrong

hope i helped

Couger / KHGamez
 
$fp = fopen('file.txt', 'w');
fwrite($fp, $variable_with_some_text_in_it);
fclose($fp);

Lots of little tricks you can do though, look through Entity's links and all of the php file functions, you should find exactly what you need.
 
handy functions for you:

function getContents($file) //returns FALSE on failure
{
$fp = @fopen($file, 'r');
if($fp === FALSE)
return FALSE;
$contents = fread($fp, filesize($file));
fclose($fp);
return $contents;
}
function putContents($file, $string) //returns TRUE/FALSE
{
$fp = @fopen($file, 'w');
if($fp === FALSE)
return FALSE;
$contents = fwrite($fp, $string);
fclose($fp);
return TRUE;
}
 
As usual, I will dissect your code 😉

function getcontents($file) { # i doubt it's a rule or anything, but i thought only class methods were supposed to be capitalized?
return implode("\n", file($file)) or return FALSE;
}

function putcontents($file, $string) {
$fp = fopen($file, 'w') or return FALSE;
fwrite($fp, $string);
fclose($fp);
return TRUE;
}

the first line of putcontents could also be something like:

if(($fp = fopen($file, 'w')) === FALSE) return FALSE;
 
Back
Top