How to write in a .txt file with PHP

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

Shaharia is a professional software engineer with more than 10 years of experience in the relevant fields. Digital ad certified, cloud platform architect, Big data enthusiasts, tech early adopters.