Article

utf8_encode and utf8_decode Deprecated

Replace the ISO-8859-1 oriented utf8_encode/utf8_decode pair with explicit mbstring or iconv conversions.

PHP 8.2 deprecated utf8_encode() and utf8_decode(). They convert between ISO-8859-1 and UTF-8 only—despite the names suggesting a universal “make this UTF-8” fix. Source: migration82 deprecated features.

# LEGACY — often wrong if source is not ISO-8859-1
$utf8 = utf8_encode($latin1);
$latin1 = utf8_decode($utf8);

# MODERN — be explicit about encodings
$utf8 = mb_convert_encoding($bytes, 'UTF-8', 'ISO-8859-1');
$bytes = mb_convert_encoding($utf8, 'ISO-8859-1', 'UTF-8');
# or iconv('ISO-8859-1', 'UTF-8', $bytes)

Modernization guidance

  • Store and transport UTF-8 end-to-end (MySQL utf8mb4, HTTP charset, JSON).
  • Delete “encode just in case” layers that double-encode.
  • When reading legacy files, detect or configure the real source encoding—do not assume Latin-1.

Scan with deprecated checker. Broader charset context: PHP 5 to modern PHP. Parent: deprecated hub.

Related scanners: PHP Version Compatibility Checker · PHP Deprecated Checker.

Related tools

Related reading