title: php regex for multiple lines with tabs and caps to csv string
body: <p>I have several text files in the format</p>
  
  <pre><code>CATEGORYA[can be multiple words but all caps] 
  [tab]Item11[multiple upper/lower case words with spaces&amp;numbers],$3.99
  [tab]Item12,$7.49[the prices sometimes don't have the $]
  etc.
  [new line]
  CATEGORYB[can be multiple words but all caps] 
  [tab]Item21,$3.99
  [tab]Item22,$7.49
  etc.
  </code></pre>
  
  <p>I would like to convert it to a csv file in the format</p>
  
  <pre><code> CATEGORYA,Item11,$3.99
   CATEGORYA,Item12,$7.49
   etc.
   CATEGORYB,Item21,$3.99
   CATEGORYB,Item22,$7.49
   etc.
  </code></pre>
  
  <p>this is the code i started with</p>
  
  <pre><code>//import file
  $file = file_get_contents('./20051019.txt', true);
  //split each category into an array
  $catarray = preg_split("[regex of somesort]", $file);
  //get number array elements
  $numcats=count($catarray)
  for ($x = 0; $x &lt; $numcats; $x++)
  {
  //split the category from the elements
  //loop through the elements replacing the tab with the category and a comma
  //add element to a string
  }
  //write string out to a file
  </code></pre>
  
  <p>Can someone please help with the regex or know a better way to do this? </p>