How to get the encoding of a uploaded .csv file?

Posted 1 year ago by berinjelablues

In my application I have a functionality that imports data from peripheral systems through ".csv" files.

Many of these files come in portuges a language full of unfamiliar accents for most programming languages.

So I need to figure out what is the encoding of each file that I uploaded to my server before importing its data into the database.

I'm using Spout to open and manipulate CSV files within my application.

Here is my code:

    $reader = Box\Spout\Reader\ReaderFactory::create(Box\Spout\Common\Type::CSV);
    $reader->setEncoding('Windows-1252');         
    $reader->setFieldDelimiter(';');
    $reader->open('../storage/app/Test/test.csv');

Thanks in advance.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.