Parse form textarea by comma or new line
<p>I have a textarea in a form that allows users to enter a list of numbers separated by either a newline or a comma. I need the numbers they entered to be entered into an array. Unfortunately, the code I have does not work all the time. If users enter comma sepated data and a newline then the comma is left in the resulting array. In addition, if they add a newline at the end of the textfield then it enters an empty value into the array. The code I have is below:</p>

<pre><code>$data = preg_split( "[\r\n]", $_POST[ 'textarea' ] );
if (count($data) == 1) {
    $string = $data[0];
    $data = explode(',', $string);
}
</code></pre>

<p>I was hoping for some help on how to get around the issues I am having.</p>
