Daffodil Computers Ltd.

Create your Own Website => HTML, PHP => Topic started by: bbasujon on January 22, 2012, 06:58:51 AM

Title: How to write in a .txt file with PHP
Post by: bbasujon on January 22, 2012, 06:58:51 AM
To write values or text in a .txt file you can follow the following process in PHP.

<?php

function test_function ()
{
return ?"Hello!";
}

$function_contents = test_function ();

$file_name = "test_file.txt";
$file_handle = fopen($file_name, 'w');
fwrite($file_handle, $function_contents);
fclose($file_handle);

?>

It will make a text file named test_file.txt and in that file this PHP code snippet will write ‘Hello’.

Thanks