title: How to write fixed width text file with PHP and MYSQL data
body: <p>I have an issue in writing fixed width text file using php and data from mysql db. Pl find below format where I have a customer table:
  customer name of 100 char width 
  customer address of 200 chars width.</p>
  
  <h2>I need to print these in the below format.</h2>
  
  <pre><code>3M India Limited                         Plot 48-51 Electronic City
  Biocon Ltd                               20th KM Hosur Road,Electronic city
  </code></pre>
  
  <p>Now my customer name keeps varying, but I need to fix this width and then print Address. Below is my code where I am manually giving the spaces which is causing the data to go haphazard when written in a text file.</p>
  
  <p>php Code:</p>
  
  <pre><code>$myFile = "testFile.txt";
  $fh = fopen($myFile, 'w') or die("can't open file");
  $stringData = "    ".$cust2[Ac_desc];
  fwrite($fh, $stringData);
  $stringData = "                                        ".$cust2[Add1]."\n";
  fwrite($fh, $stringData);
  fclose($fh);
  </code></pre>