首頁  >  文章  >  後端開發  >  php檔案操作的小例子

php檔案操作的小例子

WBOY
WBOY原創
2016-07-25 09:00:18763瀏覽
一个php文件操作的小例子,借助自定义函数实现内容读写,适合新手入门参考。

代码如下:

<?php
    ini_set('memory_limit', '-1');        //  
    ini_set("max_execution_time", "3600"); //设置超时时间  
      
    $filep='qq.txt';
      
    $str=file('qq.txt');  
     $lineCount = 0;  
       foreach( $str AS $line ) {  
           $line = str_replace( "\t", "    ", $line );  
            $tr = trim( $line );  
                if ( preg_match( "/\\*|^\*|^ {1,}\*|\/\*|\*\/|^ {1,}\/\/|^\/\//", $line ) || $tr === "" ) {  
                continue;  
                }  
                $lineCount++;  
              
            $line = str_replace( "\r", "", $line );  
             $line = str_replace( "\n", "", $line );  
               if($lineCount<5){  
                is_m('5.txt',"".$line."@qq.com\n");  
                 continue;  
               }elseif ($lineCount <10){  
                  is_m('10.txt',"".$line."@qq.com\n");  
                    break;  
               }              
            }
        function is_m($filename,$c){  
             $handle = fopen($filename, "a");  
             if ($handle) {  
             fwrite($handle, $c );  
             fclose($handle);  
            }
       }  
  ?>

您可能感兴趣的文章: php文件操作类的代码一例 一个不错的文本文件操作的php类 PHP文件操作方法问答 php中目录与文件操作详解 php目录与文件操作的实例教程



陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn