Fri, 17 May 2024


How to write to a file using PHP?

By: Peter, NetArt Media
Mon, 1 February 2021

You may take a look at the sample function below which does this.

<?
function WriteToFile($strFilename, $strText)
{
if($fp = @fopen($strFilename,"w "))
{
$contents = fwrite($fp, $strText);
fclose($fp);
return true;
}
else
{
return false;
}

}

WriteToFile('path/File.txt','test 123');

?>


Category: PHP Examples
Share this post:



See All Scripts






Subscribe for our newsletter

Receive the latest blog posts direct in your mailbox