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