Home >Backend Development >PHP Tutorial > php切割txt文档可以按KB切割吗,该怎么处理

php切割txt文档可以按KB切割吗,该怎么处理

WBOY
WBOYOriginal
2016-06-13 13:18:221221browse

php切割txt文档可以按KB切割吗
1.php切割txt文档可以按KB切割吗 
2.我在网上找人家按行切的。分是分了若干个txt、可是里面没有内容啊,下面怎么修改啊

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php $fn_in="34465.txt";
$fn_out='hgc_';
$i=0;
$n=1;
$fp_in=fopen($fn_in,'r');
while(!feof($fn_in)){
  if($i==0){
    $fp_out=fopen($fn_out.$n.'txt','w');
    $n++;
  }
  $line=fgets($fn_in);
  fputs($fp_out,$line);
  $i++;
  if($i==50000){
    close($fp_out);
    $i=0;
  }
}
if($i){
  fclose($fp_out);
  $i=0;
}
fclose($fp_in);

?>


------解决方案--------------------
1、可以
2 改成如下试试
PHP code
$fn_in="34465.txt";
$fn_out='hgc_';
$n=1;
$fp_in=fopen($fn_in,'r');
while(!feof($fp_in)){
    $fp_out=fopen($fn_out.$n.'.txt','w');
    $n++;

  $line=fgets($fp_in);
  fputs($fp_out,$line);

    fclose($fp_out);

}

fclose($fp_in);
<br><font color="#e78608">------解决方案--------------------</font><br>按rb打开, 难道不会读写文件吗。 <div class="clear">
                 
              
              
        
            </div>
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