Putting header into CSV file

Asked

Viewed 174 times

0

I have on a client’s page a log generation routine. However, I always need to add a header field on the first line. Here is the function code:

public function generateLogPMWeb($action){
    session_start('usuario');
    $logPMWeb  = $_SESSION['usuario']['id'] . ";" . $_SESSION['usuario']['id'] . "_" . $_POST['idHotel'] . "_" . date('YmdHis') . ";" . $_SESSION['usuario']['nome'] . ";" . $_SESSION['usuario']['sobrenome'] . ";" . $_SESSION['usuario']['email'] . ";" . "IC"
            . ";" . $_SESSION['usuario']['id'] . "_" . $_POST['idHotel'] . "_" . date('YmdHis') . ";" . $_POST['idHotel'] . ";" . date('Y-m-d H:i:s') . ";" . $_SESSION['buscaReserva']['dataInicio'] . ";" . $_SESSION['buscaReserva']['dataFim']
            . ";" . "Acao: " .  preg_replace('/^\s+|\n|\r|\s+$/m', '', $action) . ";\n";
    file_put_contents(Config::retorna("document_root", "root").'/logs/logPMWeb_'.date("Ymd").'.csv', $logPMWeb, FILE_APPEND);
}

I have looked on other sites the use of fputcsv function, but I do not know it serves for this case. is better to do?

  • What makes the function Config::retorna? Post the code if it’s not giant

  • I didn’t find the code, but I believe it is to configure the directory root where the CSV file will be inserted.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.