problem in lines

Hello again. With the upcoming holiday “Programmer’s Day”!
I have such a problem: here are 2 lines, for example:

|   | |   | | |
          1990
        1989  
...       .....       ....  

They need to be added to the database.
But there are no boundaries between them. And names, and the names of a different number of letters. You can only focus on | . But the wand is only from above. Hopefully I am correctly shocked!


Answer 1, Authority 100%

Well, if you suggest that this is a table, do this:

<?
$text = <<<TEXT
|   | |   | | |
          1990
        1989  
TEXT;
// $text = file_get_contents('myfile.txt');
$fields = array();
$strings = explode("\n", $text);
$header = explode('| |', $strings[0]);
for ($i = 1; $i < count($strings); $i++) {
  if (!trim($strings[$i])) continue;
  $f = array();
  $pos = 1;
  foreach ($header as $str) {
    $f[] = trim(substr($strings[$i], $pos, strlen($str)+3));
    $pos += strlen($str)+3;
    }
  if (!empty($f))
    $fields[$i] = $f;
  }
echo '<pre>';
print_r($fields);
echo '</pre>';
?>

Actually, it is working, you can run and edit.


Answer 2, Authority 50%

load the line and process

function razboy($stroka){
$st=explode (" ",$stroka);
$name=trim($st[0]);
$fam=trim($st[1]);
$date=trim($st[2]);
//    
return;
}

// And here the file loading and the rows directly into the function that is the above


Answer 3

1) We assume that all the surnames consist either from one word, or recorded according to the rules of double names / surnames:

preg_match_all("/\s*([---]+)\s*([---]+)\s*(\d{4})\s*/",$str,$matches);
//$matches[1] -  -   
//$matches[2][0] -  -   
//$matches[3][0] -   -   

Answer 4

You can also use the file

She reads the file into an array of the lines of which it consists. Well, then in the cycle apply to each line Explode () and we obtain the necessary data.