Author Topic: How to write in a .txt file with PHP  (Read 4990 times)

bbasujon

  • Administrator
  • VIP Member
  • *****
  • Posts: 1826
  • I want to show my performance at any where
    • View Profile
    • Higher Education
How to write in a .txt file with PHP
« 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
Acquire the knowledge and share the knowledge so that knowing,learning then sharing - all are the collection