>  기사  >  백엔드 개발  >  php文件操作的小例子

php文件操作的小例子

WBOY
WBOY원래의
2016-07-25 09:00:18766검색
一个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으로 문의하세요.