Home  >  Article  >  Backend Development  >  PHP文件打开、关闭、写入的判断与执行代码_PHP

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

WBOY
WBOYOriginal
2016-06-01 12:16:53859browse

如何准确的控制和判断成了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不可写入";
}
?>

PHP文件打开、关闭、写入的判断与执行代码_PHP
编程小节:注意中英文输入法的符号,特别是中文后的“;”!

Statement:
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