I have an array where one of the items is an string, I need to download that array through the web navigator as a text file (.txt) but the string item is having quotes in the text file. It is presented as 0000362367 "00100 E0.1.1" I would like to have the result without the quotes: 0000362367 00100 E0.1.1
Thanks in advance!
This is my PHP code:
$ar_result=array();
$ar=array();
$ar['u_id']= str_pad('362367', 10, "0", STR_PAD_LEFT);
$ar['NODO']='00100 E0.1.1';
$ar_result[]=$ar;
$ar['u_id']= str_pad('4352746', 10, "0", STR_PAD_LEFT);
$ar['NODO']='00100 E0.1.1';
$ar_result[]=$ar;
$filename = "test.txt";
$delimiter=" ";
header('Content-Type: application/txt');
header('Content-Disposition: attachment; filename="'.$filename.'";');
$handle = fopen('php://output', 'w');
foreach ($ar_result as $line) {
stream_filter_register("newlines", "StreamFilterNewlines");
stream_filter_append($handle, "newlines");
fputcsv($handle, $line, $delimiter);
}
class StreamFilterNewlines extends php_user_filter {
function filter($in, $out, &$consumed, $closing) {
while ( $bucket = stream_bucket_make_writeable($in) ) {
$bucket->data = preg_replace('/([^\r])\n/', "$1\r\n", $bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}