Home  >  Article  >  Backend Development  >  Judgment and execution code for opening, closing and writing PHP files_PHP tutorial

Judgment and execution code for opening, closing and writing PHP files_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:29:12807browse

How to accurately control and judge has become a "small problem" in PHP. The following is a sentence excerpted from the book.

Copy code The code is as follows:

$filename = "html/cache.txt";
$contents = "I am Zhang Bin";
if(is_writable($filename)){
if(($handle = fopen($filename,"a") )== ​​false){
echo "Failed to write file $filename";
exit();
}
if(fwrite($handle,$contents) == false){
echo "Write to file$ filename failed";
exit();
}
echo "Writing file $filename succeeded";

fclose($handle);
}else{
echo "File $filename cannot be written";
}
?>

Judgment and execution code for opening, closing and writing PHP files_PHP tutorial
Programming section: Pay attention to the symbols in the Chinese and English input methods, especially after Chinese ";"!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323486.htmlTechArticleHow to accurately control and judge has become a "small problem" in PHP. The following is excerpted from the book statement. Copy the code The code is as follows: ?php $filename = "html/cache.txt"; $conten...
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