How to remove white space after a comma from user entered data using PHP
<p>How can I remove empty space after a comma <code>,</code> that has no words using PHP.</p>

<p>Here is an entry.</p>

<pre><code>apple pie,      cherry   ,         ,       pears,      crumb cake        ,         ,
</code></pre>

<p>And Here is what I get so far.</p>

<pre><code>apple pie, cherry, , pears, crumb cake, 
</code></pre>

<p>And here is the desired output I want.</p>

<pre><code>apple pie, cherry, pears, crumb cake
</code></pre>

<p>And here is the PHP code I got so far.</p>

<pre><code>$words = preg_split('/,/', filter_var($words, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES), -1, PREG_SPLIT_NO_EMPTY);
$words = preg_replace('/\s+/', ' ', $words);
$words = array_map('trim', $words)
</code></pre>
