mabart / parsecsv-for-php

Automatically exported from code.google.com/p/parsecsv-for-php
MIT License
0 stars 0 forks source link

encoding on unparse #10

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I have little proposal for unparse method.
When I am trying send CSV to MS Excel I have to convert encoding from UTF8
to CP1250, here is the code:

$csv = new parseCSV();
$csv->encoding('utf-8', 'cp1250');
$result = $csv->unparse($csv_data, $headers, false, false, ';');

Unfortunately you don't perform encoding change in uparse() method as you
do it in load_data(). Here is my patch:

// create heading
        if ( $this->heading && !$append ) {
            foreach( $fields as $key => $value ) {
                if ( $this->convert_encoding ) $value = iconv($this->input_encoding,
$this->output_encoding, $value);
                $entry[] = $this->_enclose_value($value);
            }
            $string .= implode($delimiter, $entry).$this->linefeed;
            $entry = array();
        }

        // create data
        foreach( $data as $key => $row ) {
            foreach( $row as $field => $value ) {
                if ( $this->convert_encoding ) $value = iconv($this->input_encoding,
$this->output_encoding, $value);
                $entry[] = $this->_enclose_value($value);
            }
            $string .= implode($delimiter, $entry).$this->linefeed;
            $entry = array();
        }

Original issue reported on code.google.com by lucas...@gmail.com on 20 Oct 2008 at 10:58