FPUTCSV Custom Function

devlaravel

Dev-Sandbox

Posted on May 24, 2023

FPUTCSV Custom Function

Requirements
Values Surrounded by Double Quotes Always.
Escape Character is "
CR+LF is the newline

function fputcsv_custom($stream, $fields, $delimiter = ",", $enclosure = '"', $escape_char = '\"', $eol = "\r\n") {
    $field_arr = [];

    foreach($fields as $field) {
        $field_arr[] = $enclosure . stripslashes(str_replace($enclosure, $escape_char . $enclosure, $field)) . $enclosure;
    }

    fwrite($stream, implode($delimiter, $field_arr) . $eol);
}
Enter fullscreen mode Exit fullscreen mode

Ref: https://stackoverflow.com/questions/16942531/alternative-to-fputcsv/66682050#66682050

šŸ’– šŸ’Ŗ šŸ™… šŸš©
devlaravel
Dev-Sandbox

Posted on May 24, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related