php fgetcsv - charset encoding problems

前端 未结 2 1192
孤城傲影
孤城傲影 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: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;
        }
    }
    

提交回复
热议问题