I have a text file having 10 lines and 50 characters in each line . I want to keep first 10 characters and delete remaining characters in each line. I used the following code
<?php
$target_file = 'test.txt';
$handle = fopen($target_file, "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$new_line=substr($line,0,10)."
";
$new_handle=fopen('test.knt',"a");
fwrite($new_handle,$new_line);
}
}
fclose($new_handle);
?>
But the output file contains single line of 100 characters. New line character is not working. Any clues?