//将数组保存在文件中
function export_to_file($file, $variable) {
$fopen = fopen($file, 'wb');
if (!$fopen) {
return false;
}
fwrite($fopen, "<?php\nreturn ".var_export($variable, true).";\n?>");
fclose($fopen);
return true;
}
//将字符串写入文件
function put_to_file($file, $content) {
$fopen = fopen($file, 'wb');
if (!$fopen) {
return false;
}
fwrite($fopen, $content);
fclose($fopen);
return true;
}
php将数组或字符串写入文件
最新推荐文章于 2021-06-24 17:00:55 发布
本文介绍了两个实用的PHP函数:export_to_file用于将数组保存为PHP文件格式,而put_to_file则用于将字符串写入到文件中。这两个函数通过打开文件、写入内容并关闭文件来实现其功能。
771

被折叠的 条评论
为什么被折叠?



