comma separated value in php adding space and small square
<p>I have a text area in a form im writing pasting the comma separated value in the text area</p>

<p>like</p>

<pre><code>1,2,3,4,5

6,7,8,9,10

11,12,13,14,15
</code></pre>

<p>when i submit from its creating a csv file but the csv file in the row 1 contains header </p>

<p>its appending the 1 st row with the first row value of the comma separated value</p>

<p>i get like this ,iget the small square and the first row of comma separated value is </p>

<p>appended to the header</p>

<pre><code>id, grpname, grpid,code,name1,2,3,4,5

6,7,8,9,10

11,12,13,14,15
</code></pre>

<p>heres the code</p>

<pre><code>$csvdata = $_REQUEST['csvdata'];
$arr     = explode(",", $csvdata);
$fname   = 'file.csv';

$fp = fopen($fname, 'w');

$heading_row = array('id', 'grpname', 'grpid', 'code', 'name');
fputcsv($fp, $heading_row);

foreach ($arr as $val) {
    $v = trim($val);
    $v .= ',';

    fwrite($fp, $v, strlen($v)) || die("not written");

}
fclose($fp); 
</code></pre>
