gpt4 book ai didi

php file_put_contents ...我不能在开头追加吗?

转载 作者:行者123 更新时间:2023-12-04 10:45:14 34 4
gpt4 key购买 nike

<?php
$file = 'people.txt';
// The new person to add to the file
$person = "John Smith\n";
// Write the contents to the file,
// using the FILE_APPEND flag to append the content to the end of the file
// and the LOCK_EX flag to prevent anyone else writing to the file at the same time
file_put_contents($file, $person, FILE_APPEND | LOCK_EX);
?>

这会将内容追加到文件末尾。我想在文件的开头写最新的。

最佳答案

作为the manual page显示,没有标记来添加数据。

您需要先使用 file_get_contents() 读取整个文件,在前面加上值,然后保存整个字符串。

关于php file_put_contents ...我不能在开头追加吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4460465/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com