PHP Array Elements to CSV File Conversion

This below PHP class is to convert PHP array elements to CSV file format. This class let you write all the string array elements into CSV file and this class is more useful where you want to export data in the form of CSV file format

Export Array Elements into CSV file


class Format {
static public function arr_to_csv_line($arr) {
$line = array();
foreach ($arr as $v) {
$line[] = is_array($v) ? self::arr_to_csv_line($v) : '"' . str_replace('"', '""', $v) . '"';
}
return implode(",", $line);
}

static public function arr_to_csv($arr) {
$lines = array();
foreach ($arr as $v) {
$lines[] = self::arr_to_csv_line($v);
}
return implode("
", $lines);
}

}


Related Topic Javascript Spell Checker Embedded Code, Text Area Object
PHP Code for XML Parsing
CSV File to PHP Array Elements
HTML to Document Conversion
What are all Perl Internal Data Types

nScraps.com 2011   Privacy Policy  Terms of Service  Feedback