首頁 繪圖設計 工作閒聊 比賽活動 美術討論 標籤 圖片
PHP split files into parts (e.g. big to smaller files)
Type(Type) 2014/6/9 14:35

PHP split files into smaller parts (e.g. big to smaller files)



代碼:

<?PHP

   $how_many_part_to_split = 10;
   
   $lines = explode("\n", file_get_contents("1.bat"));
   
   $per_file_line = count($lines) / $how_many_part_to_split;
   
   $i = 0;
   $j = 0;
   $file_cnt = 1;
   $str = '';
   
   for ($i = 0; $i < count($lines); $i++)
   {
      $str .= $lines[$i]."\n";
      $j++;
            
      if ($j >= $per_file_line)
      {
         file_put_contents('bat-'.$file_cnt.'.bat', $str);
         $str = '';
         $j = 0;
         $file_cnt++;
      }
   }

   if ($j > 0 || strlen($str) > 10)
   {
      file_put_contents('bat-'.$file_cnt.'.bat', $str);
   }
   
?>


(3,383 views)
[更多討論] 討論區 Windows, Linux, Perl, PHP, C/C++, Driver, Web 理論、應用、硬體、軟體

"PHP split files into parts (e.g. big to smaller files)" 傳統頁面(電腦版)

首頁 繪圖設計 工作閒聊 比賽活動 美術討論 標籤 圖片
傳統桌面版 [ 登入/註冊 ]
© Vovo2000.com Mobile Version 小哈手機版 2024