Home > php教程 > php手册 > PHP文件打开、关闭、写入的判断与执行代码

PHP文件打开、关闭、写入的判断与执行代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 12:09:13
Original
1135 people have browsed it

如何准确的控制和判断成了PHP中的一个“小问题”,下面是从书上摘抄下来的语句。

复制代码 代码如下:


$filename = "html/cache.txt";
$contents = "我是张斌";
if(is_writable($filename)){
if(($handle = fopen($filename,"a") )== false){
echo "写入文件 $filename 失败";
exit();
}
if(fwrite($handle,$contents) == false){
echo "写入文件$filename失败";
exit();
}
echo "写入文件 $filename 成功";

fclose($handle);
}else{
echo "文件$filename不可写入";
}
?>



编程小节:注意中英文输入法的符号,特别是中文后的“;”!
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template