Heim  >  Artikel  >  Backend-Entwicklung  >  php文件操作的小例子

php文件操作的小例子

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



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn