utf8_encode

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

utf8_encodeConverts a string from ISO-8859-1 to UTF-8

Warning

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

Description

utf8_encode(string $string): string

This function converts the string string from the ISO-8859-1 encoding to UTF-8.

Note:

This function does not attempt to guess the current encoding of the provided string, it assumes it is encoded as ISO-8859-1 (also known as "Latin 1") and converts to UTF-8. Since every sequence of bytes is a valid ISO-8859-1 string, this never results in an error, but will not result in a useful string if a different encoding was intended.

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

An ISO-8859-1 string.

Return Values

Returns the UTF-8 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 example

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

The above example will output:

5a6fc3ab

See Also

  • utf8_decode() - Converts a string from UTF-8 to ISO-8859-1, replacing invalid or unrepresentable characters
  • mb_convert_encoding() - Convert a string from one character encoding to another
  • UConverter::transcode() - Convert a string from one character encoding to another
  • iconv() - Convert a string from one character encoding to another

Here you can write a comment


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

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

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