# Check Encoding and BOM Handling in a PHP CSV Upload

https://ferkesh.net/uk/baza-znan/stattia/php-csv-upload-encoding-and-bom-fixture

The first CSV column can look correct in a text editor while carrying a byte order mark that breaks header matching. Verify the accepted encoding before interpreting the data.

![Workflow. Build labeled fixtures. Check byte encoding. Verify parsed values. Confirm the round trip.](https://ferkesh.net/kb-media/ferkesh-guide-diagrams-batch-17c.svg#php-csv-upload-encoding-and-bom-fixture)

## Build a few harmless input files

Create a UTF-8 file with accents, one with a UTF-8 byte order mark and a deliberately unsupported file. Include a header and quoted field containing a comma. Record their exact expected text and encoding.

## Validate input at the import boundary

Check file size and permitted encoding before parsing. If the format allows a UTF-8 byte order mark, handle it at the start of the stream so it does not become part of the first column name. Avoid blindly removing those bytes elsewhere in data.

## Verify parsed cells

Use the application's configured delimiter, enclosure and escape rules. Test the first header and accented cell exactly. Reject invalid encoding with a useful message unless a documented input format permits a controlled conversion.

## Verify a round trip

Review a dry run or test import and export the synthetic rows again. Check that headers and accents remain correct and malformed input creates no records.

## Related guides

- [Convert CSV With Quoted Fields to JSON Safely](https://ferkesh.net/knowledgebase/article/ferkesh-csv-json-quoted-fields)
- [How to Review a WooCommerce Product CSV Before Import](https://ferkesh.net/knowledgebase/article/review-woocommerce-catalog-csv-before-import)

## Official references

- [PHP fgetcsv parsing reference](https://www.php.net/manual/en/function.fgetcsv.php)

Ferkesh Hosting. Last reviewed November 27, 2026.
