开发者

write in a file with one function

开发者 https://www.devze.com 2023-03-12 10:59 出处:网络
Is there a function where I\'m not constrained to open a file to write in it and then to close it up. I\'m searching for one function looking like this

Is there a function where I'm not constrained to open a file to write in it and then to close it up. I'm searching for one function looking like this

bool thefunction(string line, string path, string mode);

line is what I want to write in the file located from path and either from the end of the document or at the start erasing all the content defined with mode argument. Ok this sounds a bit picky, but it'开发者_运维知识库s the idea. I want to make a count up and need a file to increment the value in it.


Look into file_put_contents(). You'll still need to chmod() the file if you require different permissions than file_put_contents() creates.

Example:

// This writes a line to a file, appending to what's already there
$success = file_put_contents("/path/to/file.txt", "This string goes into the file\n", FILE_APPEND);
0

精彩评论

暂无评论...
验证码 换一张
取 消