Little code snippit that I needed today that splits a text file line by line into sequentially numbered single-line text files:
<?php
$file = fopen("data.txt", "r");
$x = 0;
while ( !feof( $file ) ) {
$fn = $x . ".txt";
$newfile = fopen( $fn, "w" );
$data = fgets($file);
fwrite( $newfile, $data );
fclose( $newfile );
$x++;
}
fclose( $file );
?>
|