0

i have a project that running on Laravel.

My function get files ( UTF8 files ) in storage then parse/insert datas into mysql table ( Mysql is in utf8mb4_unicode_ci ) .

I'm stucked because of this error on some files on insert : General error: 1366 Incorrect string value: '\xC2'

Concerned insert text fail : "La clairière d'Eole n°5"

The issue seems to be the "°" charactere. When i remove it, the insert work. No problem with the accent, juste the ° and i dont know why.

I tried some preg_replace, iconv but without success.

2 Answers2

0

Depending on the software you are using to read your CSV you may need to adjust the CSV document outputting script.

On Windows, MS Excel, expects an UTF-8 encoded CSV with its corresponding BOM character. To fullfill this requirement, you simply need to add the UTF-8 BOM character.

On a MacOS system, MS Excel requires a CSV encoded in UTF-16 LE using the tab character as delimiter.

You can use this library for parse csv file. They already include this stuff into library. https://csv.thephpleague.com/9.0/interoperability/encoding/

0

It sounds like somethings is set to ascii, not utf8, nor even latin1.

° is not available in ascii, hence the likely cause of the error. In latin1, it is hex B0. In utf8, it is C2B0. Since there error message mentions only C2 I am guessing the target character set is ascii, not latin1.

Please provide SHOW CREATE TABLE and the technique you are using for reading the files -- more than "read flat text file".

Rick James
  • 135,179
  • 13
  • 127
  • 222