使用PHP的fwrite函数将内容写入文件
发布时间:2023-07-12 18:19:10
使用PHP的fwrite函数将内容写入文件的代码如下:
<?php
$file = "example.txt";
$content = "This is an example content.";
$handle = fopen($file, "w");
if ($handle) {
fwrite($handle, $content);
fclose($handle);
echo "Content has been written to the file.";
} else {
echo "Unable to open the file.";
}
?>
以上代码将创建一个名为"example.txt"的文件,并将"This is an example content."写入该文件中。在成功写入内容后,会显示"Content has been written to the file."。如果无法打开文件,则会显示"Unable to open the file."。
