title: Removing Last Set of Brackets in String
body: <p>I have a textarea which I am inputting data into to put it into a format that I need. The data that I am inputting looks like this:</p>
  
  <p>POTTERTON PUMA 80 E (SIT/HONEYWELL) (ALL PARTS FOR THIS MODEL)<br>
  POTTERTON PUMA 80 E (SIT/HONEYWELL) (FRAME - PIPEWORK)<br>
  POTTERTON TATTLER KINGFISHER RS 46 (ALL PARTS FOR THIS MODEL)<br>
  POTTERTON PUMA 100 E (SIT/HONEYWELL (ALL PARTS FOR THIS MODEL)<br>
  POTTERTON PUMA 100 E (SIT/HONEYWELL (FRAME - PIPEWORK)</p>
  
  <p>Sometimes there are two sets of brackets, sometimes there is one and sometimes there is one unclosed bracket and then another set at the end. So once the data is processed it should look like this:</p>
  
  <p>POTTERTON PUMA 80 E (SIT/HONEYWELL),POTTERTON TATTLER KINGFISHER RS 46,POTTERTON PUMA 100 E (SIT/HONEYWELL</p>
  
  <p>So I basically want the repeat occurances removed and the last brackets removed. The code that I have written does the job for most of the data, but removes all of the brackets.</p>
  
  <p>This is my code:</p>
  
  <pre><code>&lt;?php
  if ($_SERVER['REQUEST_METHOD'] != 'POST') {
  ?&gt;
  &lt;form action="&lt;?php the_permalink(); ?&gt;" method="post"&gt;
      &lt;textarea style="width:1000px;height:350px;" name="like"&gt;&lt;/textarea&gt;
      &lt;button&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  &lt;?php
  } else {
      $fits = $_POST['like'];
      $fits = str_replace(" (","(",$fits);
      $fits = preg_replace("/\([^\)]+\)/","", $fits);
      $fits = explode("\n", str_replace("\r", "", $fits));
      $fits = array_unique($fits);
      $comma_separated = implode(', ', $fits);
      echo $comma_separated;
  }
  ?&gt;
  </code></pre>