Jump to content

Splitting a TXT file into multiple TXT files


young_coder

Recommended Posts

Read the whole file into an array. Loop through the array writing a new file for each line:

<?php
$old_file = file('old_file.txt');
$cnt = count($old_file);
for ($i=0;$i<$cnt;++$i) {
   $n = $i + 1;
   file_put_contents($n . '.txt',$old_file[$i];
}
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.