Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

doble quotes in csv export php

fputs($fp, implode(",", array_map("encodeFunc", $row))."
");



/***
 * @param $value array
 * @return string array values enclosed in quotes every time.
 */
function encodeFunc($value) {
    ///remove any ESCAPED double quotes within string.
    $value = str_replace('"','"',$value);
    //then force escape these same double quotes And Any UNESCAPED Ones.
    $value = str_replace('"','"',$value);
    //force wrap value in quotes and return
    return '"'.$value.'"';
}

$fp = fopen("filename.csv", 'w');
foreach($table as $row){
    fputs($fp, implode(",", array_map("encodeFunc", $row))."
");
}
fclose($fp);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #doble #quotes #csv #export #php
ADD COMMENT
Topic
Name
2+7 =