utf8_decode

(PHP 4, PHP 5, PHP 7, PHP 8)

utf8_decode Converts a string from UTF-8 to ISO-8859-1, replacing invalid or unrepresentable characters

Warning

This function has been DEPRECATED as of PHP 8.2.0. Relying on this function is highly discouraged.

Description

utf8_decode(string $string): string

This function converts the string string from the UTF-8 encoding to ISO-8859-1. Bytes in the string which are not valid UTF-8, and UTF-8 characters which do not exist in ISO-8859-1 (that is, code points above U+00FF) are replaced with ?.

Note:

Many web pages marked as using the ISO-8859-1 character encoding actually use the similar Windows-1252 encoding, and web browsers will interpret ISO-8859-1 web pages as Windows-1252. Windows-1252 features additional printable characters, such as the Euro sign () and curly quotes ( ), instead of certain ISO-8859-1 control characters. This function will not convert such Windows-1252 characters correctly. Use a different function if Windows-1252 conversion is required.

Parameters

string

A UTF-8 encoded string.

Return Values

Returns the ISO-8859-1 translation of string.

Changelog

Version Description
8.2.0 This function has been deprecated.
7.2.0 This function has been moved from the XML extension to the core of PHP. In previous versions, it was only available if the XML extension was installed.

Examples

Example #1 Basic examples

<?php
// Convert the string 'Zoë' from UTF-8 to ISO 8859-1
$utf8_string "\x5A\x6F\xC3\xAB";
$iso8859_1_string utf8_decode($utf8_string);
echo 
bin2hex($iso8859_1_string), "\n";

// Invalid UTF-8 sequences are replaced with '?'
$invalid_utf8_string "\xC3";
$iso8859_1_string utf8_decode($invalid_utf8_string);
var_dump($iso8859_1_string);

// Characters which don't exist in ISO 8859-1, such as
// '€' (Euro Sign) are also replaced with '?'
$utf8_string "\xE2\x82\xAC";
$iso8859_1_string utf8_decode($utf8_string);
var_dump($iso8859_1_string);
?>

The above example will output:

5a6feb
string(1) "?"
string(1) "?"

See Also

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

Technical SEO remains relevant

Technical SEO - What is it anyway? Technical SEO refers to the optimization of the technical aspects of your website. The goal is clear! ...

admin

Autor : admin
Category: SEO & Online-Marketing

What's new in PHP 8.2.10

PHP 8.2.10 is one of the latest versions of PHP, which brings a number of improvements and new features. In this article we will discuss some of the outstanding new features and improvements in this version. ...

admin

Autor : admin
Category: Software-Updates

Total Commander 11.00 (final) is available! What's new?

Total Commander, a popular file manager, has recently released its latest version, 11.00. With a variety of new features and corrections, this version offers users an enhanced and optimized experience. ...

admin

Autor : admin
Category: Software-Updates

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial