> ## Content Index
> Fetch the complete content index at: https://ostreff.info/llms.txt
> Use this file to discover other available public pages before exploring further.

# Functions utf8_encode and utf8_decode are Deprecated in PHP 8.2
- URL: https://ostreff.info/functions-utf8_encode-and-utf8_decode-are-deprecated-in-php-8-2/
- Published: 2022-12-23T14:29:37.000Z
- Updated: 2022-12-23T14:29:37.000Z
- Author: Jordan Ostreff
- Tags: #PHP

`utf8_encode` and `utf8_decode` functions, despite their names, are used to convert strings between ISO-8859-1 (Also known as "Latin 1") and UTF-8 encodings. These functions do *not* attempt to detect the actual character encoding in a given text, and always convert character encodings between ISO-8859-1 and UTF-8, even if the source text is *not* encoded in ISO-8859-1.

Although PHP includes `utf8_encode` and `utf8_decode` functions in its standard library, these functions cannot be used to detect and convert other character encodings such as Windows-1252, UTF-16, and UTF-32 to UTF-8\. Passing arbitrary text to `utf8_encode` function is prone to bugs that do not result in any warnings or errors but may lead to undesired results.

Because of the misleading function names, lack of error messages and warnings, and the lack of support for character encodings other than ISO-8859-1, ****`utf8_encode` and `utf8_decode` functions are deprecated in [PHP 8.2](https://php.watch/versions/8.2?ref=ostreff.info)**.

```bash
<?php

$utf8 = utf8_encode("\xa5\xa7\xb5"); // ISO-8859-1 -> UTF-8
$iso88591 = utf8_decode($utf8);      // UTF-8 -> ISO-8859-1

Deprecated: Function utf8_encode() is deprecated in main.php on line 3
Deprecated: Function utf8_decode() is deprecated in main.php on line 4
```

Better replacement is to use syntax:

```bash
<?php

$utf8 = mb_convert_encoding("\xa5\xa7\xb5", 'UTF-8', 'ISO-8859-1'); // ISO-8859-1 -> UTF-8
$iso88591 = mb_convert_encoding($utf8, 'ISO-8859-1', 'UTF-8');      // UTF-8 -> ISO-8859-1
```