Home  >  Article  >  Backend Development  >  A small example of php file operation

A small example of php file operation

WBOY
WBOYOriginal
2016-07-25 09:00:18810browse
一个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目录与文件操作的实例教程



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