title: Produce HTML code for tab-delimited text file
body: <p>I have to perform a task, where I'll be given a tab-delimited text file that will contain some sizechart values and I'll need to produce the HTML table markup for that table.</p>
  <p>The text file will have the following format:</p>
  <pre><code>Adidas men basketball shoes
  EU  UK  US  Foot length (1)
  18  2   6   22,3 cm.
  12  4   27  19,6 cm.
  16  7   17  24,8 cm.
  14  7.5 8   26,2 cm.
  11  9   5   32,6 cm.
  24  6   2   19,2 cm.
  26  14  4   20,7 cm.
  28  8   2   21,7 cm.
  </code></pre>
  <p>The first line is the whole chart title, the second contains the column titles, and the third till the end will be the actual size chart values.</p>
  <p>The code I produced is the following:</p>
  <pre><code>&lt;?php
  $chart = file_get_contents('test.txt');
  
  foreach (explode(&quot;\r\n&quot;, $chart) as $row) {
      $ddd[] = explode(&quot;\t&quot;, $row);
  }
  
  //echo '&lt;pre&gt;' . print_r($ddd, true) . '&lt;/pre&gt;';
  
  $html = '&lt;style&gt;table { table-layout: fixed; font-size: 14px; text-align: center; }
  table thead th, table thead td { padding: 6px; }
  table tbody th, table tbody td { padding: 3px; }
  table thead { color: #fff; }
  table thead tr&gt;* { background: #b42129; }
  table thead tr:nth-child(2n)&gt;* { background: #5f5f5f; }
  table tbody tr:nth-child(2n)&gt;* { background: #ebebeb; }&lt;/style&gt;';
  
  $html .= '&lt;table&gt;';
  
  foreach ($ddd as $k =&gt; $row) {
      if ($k === 0) {
          $html .= '&lt;thead&gt;&lt;tr&gt;&lt;th colspan=&quot;' . count($ddd[1]) . '&quot;&gt;' . $row[0] . '&lt;/th&gt;&lt;/tr&gt;';
      } elseif ($k === 1) {
          $html .= '&lt;tr&gt;';
  
          foreach ($row as $ggg) {
              $html .= '&lt;th&gt;' . $ggg . '&lt;/th&gt;';
          }
  
          $html .= '&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;';
      } else {
          $html .= '&lt;tr&gt;';
  
          foreach ($row as $y =&gt; $bbb) {
              if ($y === 0) {
                  $html .= '&lt;th&gt;' . $bbb . '&lt;/th&gt;';
              } else {
                  $html .= '&lt;td&gt;' . $bbb . '&lt;/td&gt;';
              }
          }
  
          $html .= '&lt;/tr&gt;';
      }
  }
  
  $html .= '&lt;/tbody&gt;&lt;/table&gt;';
  
  echo $html;
  </code></pre>
  <p>The code works just fine but it looks a bit sloppy. Could someone take a look in case there is something that can be done to tidy it up a little? TIA</p>