title: making html table columns optionally sortable
body: <p>I have an html table that is populated from a text file, formatted and semi colon separated.
  I would like the user to have the option of sorting alphabetically with either of the columns when clicking on the column name (header).</p>
  
  <p>How do I do this in php?? Or is there another way of doing this? Thanks for your help.</p>
  
  <p>Sample raw data/input looks like this:</p>
  
  <pre><code>TYPE=abc;PART=georgetown;FILE=goog_abc.dat.2010122211.gz
  TYPE=xyz;PART=ucny;FILE=aol_xyz.dat.2010122209.gz
  </code></pre>
  
  <p>Php code for table:</p>
  
  <pre><code>$lines = preg_split('~\s*[\r\n]+\s*~', file_get_contents('/temp/tab.txt'));
  foreach($lines as $i =&gt; $line) {
      $pairs = explode(';', $line);
      foreach($pairs as $pair) {
          list($column, $value) = explode('=', $pair, 2);
          $columns[$column] = true;
          $rows[$i][$column] = $value;
      }
  }
  $columns = array_keys($columns); 
  echo '&lt;table&gt;&lt;thead&gt;&lt;tr&gt;';
  foreach($columns as $column) {
      echo '&lt;th&gt;'.$column.'&lt;/th&gt;';
  }
  echo '&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;';
  foreach ($rows as $row) {
      echo '&lt;tr&gt;';
      foreach($columns as $column){
                 echo '&lt;td&gt;'.$row[$column].'&lt;/td&gt;';
      }
      echo '&lt;/tr&gt;';
  }
  echo '&lt;/tbody&gt;&lt;/table&gt;';
  </code></pre>