<?php $file = file ( 'filename.txt' ); foreach ( $file as $word ) { $word = trim ( $word ); if ( $word == '' ) { continue; } $len = strlen ( $word ); $fo = fopen ( $len . ".txt", "ab" ); fwrite ( $fo, $word . "\r\n" ); fclose ( $fo ); } ?>
<?php $filename = 'filename.txt'; $file = file ( $filename ); $max_len = 10; $main = fopen ( $filename, 'wb' ); foreach ( $file as $word ) { $word = trim ( $word ); if ( $word == '' ) { continue; } $to_main = substr ( $word, 0, $max_len ); $to_add = substr ( $word, $max_len ); fwrite ( $main, $to_main ); if ( $to_add == '' ) { $add = fopen ( 'add.txt', 'ab' ); fwrite ( $add, $to_add ); fclose ( $add ); } } fclose ( $main ); ?>