jabranr / csv-parser

PHP client to parse CSV data from a path, file, stream, resource or string into indexed or associative arrays.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Explode of CSV with invalid characters

vatri opened this issue · comments

I just work for on a commercial project. The client of mine wants to import some CSV that includes a strange characters... OpenOffice does replace these with "[?]" but your CSV parser recognizes these characters as \n and moves the rest of the line into new line...

Anyways,
I added following function and called it within fromString(), fromFile() and fromStream() methods.

private function _removeStrangeCharacters($string){
    return mb_convert_encoding($string, 'UTF-8', "UTF-8");
}

i.e.

public function fromFile( $file ) {
    if ( file_exists($file) && is_readable($file) ){
         $this->data = file_get_contents($file);
         $this->data = $this->_removeStrangeCharacters($this->data);
     }
     return $this;
}

I actually worked on 2.0.1 version... Not sure if this is fixed in new versions - and don't have time to check now. But I hope to see this problem solved in a following releases. :)

@vatri Thank you. I would actually run couple of tests against this if possible and yes, will consider it for next milestone.

Awesome! I'll consider your script again for future CSV parsing purpose.