Example 1 — Convert Latin-1 to UTF-8
A Latin-1 letter uses one byte. In UTF-8, accented letters use two. The deprecation notice is hidden here to keep the output clean.
<?php
error_reporting(E_ALL & ~E_DEPRECATED);
$latin = "caf\xE9";
$utf8 = utf8_encode($latin);
echo strlen($latin), PHP_EOL;
echo strlen($utf8), PHP_EOL;
echo $utf8, PHP_EOL; How It Works
- Latin-1 string.
\xE9is the single byte for é in ISO-8859-1. - Encode. utf8_encode() turns it into the two-byte UTF-8 form.
- Compare lengths. The string grows from 4 bytes to 5.
- Print it. A UTF-8 terminal shows
café.

