如何用PHP写入文件? [英] How to write into a file in PHP?

查看:95
本文介绍了如何用PHP写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个免费的PHP服务器上的脚本:

I have this script on one free PHP-suppoting server:

<html>
<body>

<?php
$file = fopen("lidn.txt","a");


fclose($file);
?>

</body>
</html>

它确实创建了lidn.txt文件,但它是空的。

it does create the lidn.txt file, but it's empty.

我想创建一个文件,并写入一些东西,
例如这行猫追逐老鼠,我该怎么办?

I want to create a file and to write something into it, for example this line "Cats chase mice", how can I do it?

推荐答案

您还可以使用更高级的功能,如 file_put_contents($ filename,$ content)好的工作!

You can also use a higher-level function like file_put_contents($filename, $content) which does a really good job!

这篇关于如何用PHP写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆