title: PHP Take TEXTAREA value and turn into Comma Separated List
body: <p>I'm taking a TEXTAREA value and I need it to always be in the same format for every input.</p>
  
  <p>This is what I have tested from the codes provided in answers:</p>
  
  <pre><code>$tags = mysql_real_escape_string(strip_tags($purifier-&gt;purify($_POST['tags'])));
  $tags = preg_replace('/\W/',' ', $tags);
  $tags = preg_replace('/\s+/', ' ', $tags);
  $tags = trim($tags);
  $tags = explode(' ', $tags);
  $tags = array_unique($tags);
  $tags = implode(',', $tags);
  
  $tagstoadd = mb_strtolower($tags);
  </code></pre>
  
  <p>The output of anything they insert should be</p>
  
  <p>'tag,tag,tag,tag,tag,tag'</p>
  
  <p>If for instance, the input is 'Tag Tag Tag, Tag, Tag'</p>
  
  <p>It needs to be output as 'tag,tag,tag,tag,tag'</p>
  
  <p>What I have currently adds an extra comma for spaces, which isn't what I intend, if there is already a comma. And there can't be duplicates either. How can I accomplish this?</p>