php写Json文件操作

版权声明:如果对您有帮助,跪求点赞!本文为博主原创作品,转载请声明出处! https://blog.csdn.net/u011086209/article/details/90634525

覆盖写入,不存在则创建

<?php
echo file_put_contents("test.txt","yudabo");
?>

追加写入,lock防止多人同时写入

<?php
$json_data = '{ "name": "yudabo" }';
$file = 'test.json';

// 向文件追加写入内容
// 使用 FILE_APPEND 标记,可以在文件末尾追加内容
//  LOCK_EX 标记可以防止多人同时写入
file_put_contents($file, $json_data, FILE_APPEND | LOCK_EX);
?>

猜你喜欢

转载自blog.csdn.net/u011086209/article/details/90634525