php fgetcsv - charset encoding problems

前端 未结 2 1182
孤城傲影
孤城傲影 2020-12-16 17:51

Using PHP 5.3 fgetcsv function, I am experiencing some problems due to encoding matters. Note that that file has spanish \"special\" latin characters like graph

相关标签:
2条回答
  • 2020-12-16 18:44

    This is likely to do with the way excel encodes the file when saving.

    Try uploading the .xls file to google docs and downloading as a .csv

    0 讨论(0)
  • 2020-12-16 18:48

    Try this:

    function convert( $str ) {
        return iconv( "Windows-1252", "UTF-8", $str );
    }
    
    public function getRow()
    {
        if (($row = fgetcsv($this->_handle, 10000, $this->_delimiter)) !== false) {
            $row = array_map( "convert", $row );
            $this->_line++;
            return $this->_headers ? array_combine($this->_headers, $row) : $row;
        } else {
            return false;
        }
    }
    
    0 讨论(0)
提交回复
热议问题