Level 67
http://php.net/manual/en/function.mb-detect-encoding.php
Set the 3rd parameter to true for best results.
$str = file_get_contents('../storage/app/Test/test.csv');
$encoding = mb_detect_encoding($str, mb_detect_order(), true);
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.
http://php.net/manual/en/function.mb-detect-encoding.php
Set the 3rd parameter to true for best results.
$str = file_get_contents('../storage/app/Test/test.csv');
$encoding = mb_detect_encoding($str, mb_detect_order(), true);
Please or to participate in this conversation.