php中file_put_contents的使用方法

file_get_contents和file_put_contents是一对好基友,file_get_contents可以用来爬取网页的内容,file_put_contents可以把内容保存到本地文件中

以下是file_put_contents的详细用法

file_put_contents(file, data, mode, context)

参数 描述 file 必需。规定要写入数据的文件。如果文件不存在,则创建一个新文件。

data 可选。规定要写入文件的数据。可以是字符串、数组或数据流。

mode 可选。规定如何打开/写入文件。

可能的值:

FILE_USE_INCLUDE_PATH

FILE_APPEND

LOCK_EX

context 可选。规定文件句柄的环境。 context 是一套可以修改流的行为的选项。若使用 null,则忽略。

<?php

file_put_contents("/var/www/html/test.txt","file content",FILE_APPEND);

error_log(print_r($array_data, 1),3,'/tmp/eoosou');

$array = array("username"=>"yansy");

error_log(var_export($array,1),3,'/tmp/log.txt');

?>

    A+
发布日期:2022年04月29日  所属分类:php

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: