Example 1 — Detect UTF-8
Ask which encoding a normal accented word uses.
<?php
$text = "café";
echo mb_detect_encoding($text, ["UTF-8", "ISO-8859-1"], true), PHP_EOL; How It Works
- Give a list of encodings to try.
- PHP tests
UTF-8first. The text is valid UTF-8. - It returns the first match.
- Strict mode makes sure the match is exact.

