PHPでtxtファイルを作成し、テキストコンテンツを書き込みます

<!DOCTYPE html>
<html>

<body>

<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "Bill Gates\n";
fwrite($myfile, $txt);
$txt = "Steve Jobs\n";
fwrite($myfile, $txt);
fclose($myfile);
?>
 
</body></html>

その結果、stitermフォルダーにnewfile.txtフォルダーが自動的に作成され、中身は次のようになります。

Bill Gates
Steve Jobs

おすすめ

転載: blog.csdn.net/weixin_40945354/article/details/108423581