Jump to content

[SOLVED] New Line Character in File


heminfotech

Recommended Posts

I want to read a file where there are more than 60 New Line Characters. and this 60 Lines equals to one record so I have to create a reader and writer for that File. If U can also help me on how to make this 60 lines a record. I will be obliged for it.

Ok.. on the assumption that each record is exactly 60 lines, you could do something like the following:

 

$fp = fopen('file.txt', 'r') or die("Could not open file\n");
$line_count = 0;
$record = '';
$records = array();
while (!feof($fp)) {
  $line = fgets($fp);
  $line_count++;
  if ($line_count < 60) {
    # Add to current record
    $record .= $line;
  } else {
    # Completed one record
    $records[] = $record;
    $record = '';
    $line_count = 0;
  }
}

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.