如何用PHP写入文件?
我在一个免费的PHP支持服务器上有这个脚本:
<html>
<body>
<?php
$file = fopen("lidn.txt","a");
fclose($file);
?>
</body>
</html>
它将创建文件 ,但它是空的。lidn.txt
如何创建一个文件并在其中写入一些内容,例如“猫追逐老鼠”行?
我在一个免费的PHP支持服务器上有这个脚本:
<html>
<body>
<?php
$file = fopen("lidn.txt","a");
fclose($file);
?>
</body>
</html>
它将创建文件 ,但它是空的。lidn.txt
如何创建一个文件并在其中写入一些内容,例如“猫追逐老鼠”行?
考虑 fwrite():
<?php
$fp = fopen('lidn.txt', 'w');
fwrite($fp, 'Cats chase mice');
fclose($fp);
?>