Question: So i made test code:

```
$fopen = fopen('./mydata.csv',"r");    
$data = fgetcsv($fopen, 1000, ",");
fclose($fopen);
$fp = fopen('mynewdata.csv','a');
fputcsv($fp,$data,',');
fclose($fp);    

```

Content of mydata.csv file:

> 
> string "some thing", sec string,next string
> 
> 
> 

New content of mynewdata.csv file:

> 
> "string ""some thing"""," sec string","next string"
> 
> 
> 

My question is: Where this ' " ' comes from. What i do wrong that my output is different than input.

Few more obserwations:

When i do test like, with enclosure: '' -> empty string:

```
$data = fgetcsv($fopen, 1000,',','');
print_r($data);

```

It print's nothing insted of array with 2 rows, and that's the error i got from logs:
" FastCGI sent in stderr: "PHP message: PHP Warning: fgetcsv(): enclosure must be a **character**" So what would be the other option to give as the enclosure an empty string.

Answer: 
As you can see by the [`fputcsv` documentation](http://dk1.php.net/fputcsv):

> 
> int fputcsv ( resource $handle , array $fields [, string $delimiter = ',' [, string $enclosure = '"' ]] )
> 
> 
> 

The last parameter is the enclosure. Since you haven't defined yours, it defaults to `"`, and then it has to escape your quote by placing a double quote.

To get rid of this, simply specify an empty string:

```
$fopen = fopen('./mydata.csv',"r");    
$data = fgetcsv($fopen, 1000, ",");
fclose($fopen);
$fp = fopen('mynewdata.csv','a');
fputcsv($fp,$data,',','');
//                    ^^
fclose($fp); 

```

But *why* does it do this by default?!
--------------------------------------

To avoid errors if you have commas in your strings. Imagine the following:

```
$data = array('my string', 'is a great string', 'and it is, very nice');

```

With an enclosure it would result in the following:

```
"my string","is a great string","and it is, very nice"

```

*Without* an enclosure, it would result in the following:

```
my string,is a great string,and it is, very nice

```

Which would be misinterpreted as 4 values instead of 3.
Thank you guys for your replay. But the answer is different. I step on php bug:
<https://bugs.php.net/bug.php?id=51496>

If some of you guy's out there know the solution, please write it. 
My php version 5.4.6. 

Edit.

So to get rid of that problem insted of function fgetcsv and fputcsv i did way around:

```
$handle = fopen('./mydata.csv','r'); 
$data = fgets($handle);
$data = str_replace(', ','@!#$',$data);
$data = explode(',',$data);
$data = str_replace('@!#$',', ',$data);

$fp = fopen('mynewdata.csv','a');
$data = implode($data,',');
fwrite($fp, $data."\n");
fclose($fp);
fclose($handle);

```

The other solution. Insted of str\_replace, explode, str\_replace you can do:

```
$handle = fopen('./mydata.csv','r'); 
$data = fgets($handle);
$data = explode('","', preg_replace('/([^ ]),([^ ])/', '$1","$2', $data));
fclose($handle);
...

```