title: Text align for a csv file reader in php
body: <p>The following code reads a .csv file and generates an HTML table. I want to decide which column (field) will have all data aligned left or center. How can I do that?</p>
  <pre><code>&lt;?php  
  $colhead = &quot;#9BBB59&quot;;
  $colrow = &quot;#D7E4BC&quot;;
  echo &quot;&lt;table style=\&quot;text-align: left; margin-left: auto; margin-right: auto; font-family: Helvetica,Arial,sans-serif; border: 1px solid black; padding:1px; border-spacing: 1px; border-collapse: separate; frame=\&quot;border\&quot; rules=\&quot;none\&quot;&gt;&quot;;
  echo &quot;&lt;tbody&gt;&quot;;
  $row = 1;
  if (($handle = fopen(&quot;myfile.csv&quot;, &quot;r&quot;)) !== FALSE) {
   while (($data = fgetcsv($handle, 1000, &quot;;&quot;)) !== FALSE) {
      $num = count($data);
      if ($row == 1) {
          echo &quot;&lt;tr&gt;&quot;;
      }else{
          echo &quot;&lt;tr&gt;&quot;;
      }
     
      for ($c=0; $c &lt; $num; $c++) {
          if(empty($data[$c])) {
             $value = &quot;&amp;nbsp;&quot;;
          }else{
             $value = $data[$c];
          }
          if ($row == 1) {
  
  // ------------- HEADER
  echo &quot;&lt;td style=\&quot;background-color:$colhead; text-align:center; vertical-align:middle; color:#ffffff; font-size:16px; font-weight:bold; padding:4px;\&quot;&gt;&amp;nbsp;&amp;nbsp;&quot;.$value.&quot;&amp;nbsp;&amp;nbsp;&lt;/td&gt;&quot;;
   }else{
  
  // ------------- GENERIC ROW
  echo &quot;&lt;td style=\&quot;background-color:$colrow; text-align:left; vertical-align:middle; color:#000000; font-size:14px; padding:4px; border:0px solid\&quot;&gt;&amp;nbsp;&amp;nbsp;&quot;.$value.&quot;&amp;nbsp;&amp;nbsp;&lt;/td&gt;&quot;;
  
          }
      }
     
      if ($row == 1) {
          echo '&lt;/tr&gt;';
      }else{
          echo '&lt;/tr&gt;';
      }
      $row++;
  }
  
  echo '&lt;/tbody&gt;&lt;/table&gt;';
  echo '&lt;/center&gt;';   
  fclose($handle);
  }
  ?&gt;
  </code></pre>