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');
?>