doble quotes in csv export php

Solutions on MaxInterview for doble quotes in csv export php by the best coders in the world

showing results for - "doble quotes in csv export php"
David
04 Oct 2016
1fputs($fp, implode(",", array_map("encodeFunc", $row))."\r\n");
2
3
4
5/***
6 * @param $value array
7 * @return string array values enclosed in quotes every time.
8 */
9function encodeFunc($value) {
10    ///remove any ESCAPED double quotes within string.
11    $value = str_replace('\\"','"',$value);
12    //then force escape these same double quotes And Any UNESCAPED Ones.
13    $value = str_replace('"','\"',$value);
14    //force wrap value in quotes and return
15    return '"'.$value.'"';
16}
17
18$fp = fopen("filename.csv", 'w');
19foreach($table as $row){
20    fputs($fp, implode(",", array_map("encodeFunc", $row))."\r\n");
21}
22fclose($fp);