Search
 
SCRIPT & CODE EXAMPLE
 

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);
Comment

PREVIOUS NEXT
Code Example
Php :: Laravel Nested whenLoaded 
Php :: public variable in php 
Php :: conditional validation laravel based on role 
Php :: Regullar date format for php 
Php :: nginx php-fpm 
Php :: entrust laravel 
Php :: where statement multiple argument in codeigniter 
Php :: get last name user 
Php :: php foreach multidimensional array recursive 
Php :: php artisan preset bootstrap 
Php :: change sender name laravel 
Php :: check if config exist laravel 
Php :: single sign on php script 
Php :: create model and migration laravel 
Php :: Wordpress pagination custom arrow 
Php :: get time ISO 8601 wordpress 
Php :: Route [login] not defined.Route [login] not defined. 
Php :: php fpdf in phpmailer 
Php :: php function return multiple values 
Php :: check url parameter if not redirect wordpress 
Php :: php warning array to string conversion 
Php :: php How to remove from a multidimensional array all duplicate elements including the original 
Php :: guzzle download file 
Php :: coinbase commerce laravel 
Php :: php file hash 
Php :: curlopt_postfields php example 
Php :: delete a migration laravel 
Php :: netchain media 
Php :: laravel verify email custom url 
Php :: Laravel whereHas with count 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =