Search code examples
phpstringquotes

How delete quotes from str_pad in PHP


I'm writting file and in a field, I need write 6 caracters from number and complete with space. I use then str_pad

str_pad($globalResult['Folio'], 6, ' ', STR_PAD_LEFT)

But In my file I see it's adding quotes around my field. I put for example 6 and I've in return " 6". I want same but without quotes.

I try

trim(str_pad($globalResult['Folio'], 6, ' ', STR_PAD_LEFT),'"')

Or

str_pad($globalResult['Folio'], 6, ' ', STR_PAD_LEFT))

But I've always " 6" in my file.

I try $globalResult['Folio'] only I've 6.

Thanks for your help

Update

Here a little more code:

$df = fopen("facturation/PDF/Export/ECRITURE.WIN", 'w');

//BOUCLE D'AFFICHAGE DES FACTURES====
//On parcourt la liste des factures
$DB_GLOBAL->DbQuery($req)or die(mysql_error());
$NumRow=1;
while($globalResult = $DB_GLOBAL->DbNextRow())
{
    $inf = [$globalResult['Typ'],$globalResult['Dte'],str_pad($globalResult['Folio'], 6, ' ', STR_PAD_LEFT), str_pad($NumRow, 6, ' ', STR_PAD_LEFT)];
    fputcsv($df, $inf, '|');
    $NumRow++;
}
if (fclose($df) === true) {
echo 'Fichier cree';

} else {
      echo 'Erreur : contactez l\'administrateur.';
}

And the result in file

VE|05012015|" 1"|" 1" VE|05012015|" 1"|" 2" VE|05012015|" 1"|" 3" VE|06012015|" 1"|" 4" VE|06012015|" 1"|" 5" VE|06012015|" 1"|" 6" VE|06012015|" 1"|" 7" VE|07012015|" 1"|" 8" VE|07012015|" 1"|" 9" VE|07012015|" 1"|" 10" VE|08012015|" 1"|" 11" VE|08012015|" 1"|" 12" VE|08012015|" 1"|" 13" VE|08012015|" 1"|" 14" VE|08012015|" 1"|" 15" VE|09012015|" 1"|" 16" VE|09012015|" 1"|" 17" VE|09012015|" 1"|" 18" VE|09012015|" 1"|" 19" VE|10012015|" 1"|" 20" VE|10012015|" 1"|" 21"

I try to force enclosure parameter of fputcsv, "\n", "\0", null but nothing like I want. I need to export some datas on another application. I need to respect format asked


Solution

  • I find here

    fputs($df, implode($inf, ',')."\n");
    

    Work perfectly