PHP将字符串添加到文本文件 [英] PHP Add string to text file
本文介绍了PHP将字符串添加到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
写入php中的文本文件
Possible Duplicate:
writing to a text file in php
说我想将字符串$ ip添加到同一目录中的文本文件ip.txt中.我目前正在使用file_get_contents
从文本文件中读取.
Say I wanted to add the string $ip to the text file ip.txt in the same directory. I am currently using file_get_contents
to read from the text file.
推荐答案
You could use file_put_contents
<?php
$ip = "foo";
file_put_contents("ip.txt", $ip, FILE_APPEND);
?>
FILE_APPEND
将附加文本.缺少此标志将导致文件覆盖.
FILE_APPEND
will append the text. Absence of this flag will cause file-overwriting.
这篇关于PHP将字符串添加到文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文