首页 > php框架 > PHP写入文件实现技巧分享

PHP写入文件实现技巧分享

我们知道,在

PHP写入文件判断是否能被写:

< ?php  

  1. $file = dirlist.php;  
  2. if (is_writable($file) 
    == false) {  
  3. die("我是鸡毛,我不能");  
  4. }  
  5. ?> 
  6.  

能写了的话可以使用file_put_contents函数实现PHP写入文件:

  1. < ?php  
  2. $file = dirlist.php;  
  3. if (is_writable($file) == false) {  
  4. die(我是鸡毛,我不能);  
  5. }  
  6. $data = 我是可鄙,我想要;  
  7. file_put_contents ($file, $data);  
  8. ?> 
  9.  

file_put_contents函数在php5中新引进的函数(不知道存在的话用function_exists函数先判断一下)低版本的php无法使用,可以使用如下方式实现PHP写入文件:

  1. $f = fopen($file, w);  
  2. fwrite($f, $data);  
  3. fclose($f);  


本文地址:http://www.phprm.com/frame/php1003996.html

转载随意,但请附上文章地址:-)

标签:none

发表留言