Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Accents problem in view
  • Hi,

    I've parsed a csv file in a controller, done a print_r of the resulting array and everything was fine.
    However when the information was passed from the controller to the view all the accents (the file contains French text) became illegible.

    I've checked the config file of the application and the charset is UTF-8 & in the generated view there is a meta charset with the utf-8 value.

    The code of the controller and view can be found here: http://pastebin.com/NV1ajtFg

    Does anyone know why the accents aren't working?
    Thanks in advance 
  • HarroHarro
    Accepted Answer
    This CSV isn't an Excel (or other Windows) export by any chance?

    Windows exports are never in UTF-8, so you need to convert them to be usable. I struggled a lot with that recently.
  • Hi Harro,

    Yes the file did come from a windows Excel export.
    I just followed the instructions in this thread to convert the file and it works fine: http://stackoverflow.com/questions/4221176/excel-to-csv-with-utf8-encoding

    Thanks for the help.
  • HarroHarro
    Accepted Answer
    What a long and very complicated set of instructions. ;-)

    This will do the trick quite nicely:
            // read the file
            $data = \File::read($file['file'], true);

            // convert it to UTF-8 if it's a windows upload
            if (mb_detect_encoding($data, 'ISO-8859-1, UTF-8') == 'ISO-8859-1')
            {
                $data = mb_convert_encoding($data, 'UTF-8', 'ISO-8859-1');
            }
  • Great, thanks for the answer.

    It seems to be much simpler than everything I had to go through.
  • This works for me, for an application that imports a lot of CSV files (with accented characters) on a daily basis, that are made with Excel.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion