php两种方法将对象或者数组写入一个文本文件

分类:php

 第一种:

<?php
$filename = 'test.txt';
$somecontent = "this is test string.";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "不能打开文件 $filename";
exit;
}
// 将$somecontent写入到我们打开的文件中。
if (fwrite($handle, $somecontent) === FALSE) {
echo "不能写入到文件 "e;{$filename}"e;";
exit;
}
echo "已把"e;{$somecontent}"e;写入到文件"e;{$filename}"e;";
fclose($handle); //将指针关闭
} else {
echo "文件{$filename}不可写.";
}
?>

第二种:
<?php
$filename = "test.txt";
$content = "this is test string.";
$put = file_put_contens($filename,$content);
if(!put)
exit("write failed");
echo "write success";
?>
本文链接: php两种方法将对象或者数组写入一个文本文件
版权所有:布士收藏夹在网络收集,如有侵犯你的权利, 请联系QQ:641868752。

评论

发表评论

*

* (显示gravatar头像)

Ctrl+Enter快捷回复

© 2014 布士收藏夹 all rights reserved.