PHP utf8_decode() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In PHP, utf8_decode() converts a UTF-8 string to the ISO-8859-1 (Latin-1) encoding.

It is deprecated since PHP 8.2. Use mb_convert_encoding() or iconv() instead.

Syntax

Call utf8_decode() with the values you need. Start with this line.

PHP
$latin = utf8_decode($utf8);
CallWhat it does
utf8_decode("café")Returns the Latin-1 bytes for "café", which is 4 bytes long.
utf8_decode("€")Returns "?" because the euro sign is not in Latin-1.

Deprecated since PHP 8.2 and will show a deprecation notice. Replace it with mb_convert_encoding($string, "ISO-8859-1", "UTF-8").

Library declarations
PHP
utf8_decode(string $string): string

Parameters

ParameterDescription
stringRequired. A UTF-8 encoded string.

Return Value

Return ValueDescription
stringThe string encoded as ISO-8859-1. Characters outside Latin-1 become "?".

PHP Examples

Example 1 — Convert UTF-8 to Latin-1

A UTF-8 letter such as é takes two bytes, but in Latin-1 it takes one. This example hides the PHP 8.2 deprecation notice so the output stays clean. Save the file as UTF-8.

PHP
<?php
error_reporting(E_ALL & ~E_DEPRECATED);

$utf8  = "café";
$latin = utf8_decode($utf8);

echo strlen($utf8), PHP_EOL;
echo strlen($latin), PHP_EOL;

How It Works

  1. Start with UTF-8. The letter é uses two bytes, so "café" is 5 bytes.
  2. Decode. utf8_decode() converts it to Latin-1.
  3. One byte per letter. Now the string is 4 bytes.
  4. Compare lengths. The two strlen() calls show 5 and 4.

Example 2 — Characters Outside Latin-1

Latin-1 cannot hold every symbol. Anything missing is replaced with a question mark.

PHP
<?php
error_reporting(E_ALL & ~E_DEPRECATED);

var_dump(utf8_decode("€"));
var_dump(utf8_decode("A"));

How It Works

  1. Euro sign. It is not part of ISO-8859-1.
  2. Replacement. PHP substitutes "?", so data is lost.
  3. Plain ASCII. The letter A survives unchanged.
  4. Be careful. The conversion cannot be reversed for lost characters.

Example 3 — Use mb_convert_encoding() Instead

The modern replacement gives the same result without a deprecation notice.

PHP
<?php
error_reporting(E_ALL & ~E_DEPRECATED);

$utf8 = "café";
$old  = utf8_decode($utf8);
$new  = mb_convert_encoding($utf8, "ISO-8859-1", "UTF-8");

var_dump($old === $new);
echo strlen($new), PHP_EOL;

How It Works

  1. Old way. utf8_decode() is deprecated.
  2. New way. mb_convert_encoding() takes the target and source encodings.
  3. Same bytes. The strict comparison returns true.
  4. Recommended. Use the mb function in all new code.

Frequently Asked Questions

utf8_decode() converts a UTF-8 encoded string into ISO-8859-1 (Latin-1). Characters that do not exist in Latin-1 become question marks.
string utf8_decode(string $string). It takes a UTF-8 string and returns the Latin-1 version.
Yes. It has been deprecated since PHP 8.2. Use mb_convert_encoding($s, "ISO-8859-1", "UTF-8") or iconv() instead.
The original text has characters that Latin-1 cannot represent, such as the euro sign or emoji. They are replaced with "?".
utf8_encode() converts ISO-8859-1 to UTF-8. It is also deprecated since PHP 8.2.

Next: utf8_encode()

utf8_encode() converts an ISO-8859-1 (Latin-1) string to UTF-8.

utf8_encode() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful