title: How to explode a text into an array by end of line and then explode it again by colon using PHP?
body: <p>I'm trying to read a structured log file, explode it by line and after that by colon.</p>
  
  <p>I'm trying in two diferent approaches <code>fgets</code> and <code>file_get_contents</code>, but in both I'm able to reach only one or the other objective (explode by line <strong>or</strong> by colon).</p>
  
  <p>Here we have the code:</p>
  
  <pre><code>&lt;?php
  
  // using fgets
  $file = fopen('/var/www/html/PU1PAX.log', 'r');
  
  while (!feof($file)) { // while not end of file
      $content = fgets($file); // get file's content
      $handle = explode(':', $content); // and explode by string
  
      echo '&lt;pre&gt;';
      print_r($handle);
      echo '&lt;/pre&gt;';
  }
  fclose($file);
  
  
  // using file_get_contents
  $file = '/var/www/html/PU1PAX.log';
  $content = file_get_contents($file);
  $handle = explode(PHP_EOL, $content);
  
  echo '&lt;pre&gt;';
  print_r ($handle);
  echo '&lt;/pre&gt;';
  </code></pre>
  
  <p>The first part of the code prints one array to each line:
      Array
      (
          [0] => START-OF-LOG
          [1] =>  3.0
      )</p>
  
  <pre><code>Array
  (
      [0] =&gt; LOCATION
      [1] =&gt;  DX
  )
  
  Array
  (
      [0] =&gt; CALLSIGN
      [1] =&gt;  PU1PAX
  )
  
  Array
  (
      [0] =&gt; CLUB
      [1] =&gt;   
  )
  
  Array
  (
      [0] =&gt; CONTEST
      [1] =&gt;  CQRJVHF
  )
  </code></pre>
  
  <p>The second part prints only one array with all lines ordered:</p>
  
  <pre><code>Array
  (
      [0] =&gt; START-OF-LOG: 3.0
      [1] =&gt; LOCATION: DX
      [2] =&gt; CALLSIGN: PU1PAX
      [3] =&gt; CLUB:  
      [4] =&gt; CONTEST: CQRJVHF
  )
  </code></pre>
  
  <p>For the first, I would like to find a solution to group all this arrays together, as the content is more or less separated and workable.</p>
  
  <p>For the second, it would be interesting if I could change the array in a way that I could explode it again (this time by colon) to have the first part of the string as the array's keys and the second part as the array's values like the following example:</p>
  
  <pre><code>Array
  (
      [START-OF-LOG] =&gt; 3.0
      [LOCATION] =&gt; DX
      [CALLSIGN] =&gt; PU1PAX
      [CLUB] =&gt;   
      [CONTEST] =&gt; CQRJVHF
  )
  </code></pre>
  
  <p>But I'm complete stuck... :-(</p>