Example 1 — Count Characters
Compare iconv_strlen() with strlen().
<?php
$text = "Héllo";
echo strlen($text), PHP_EOL;
echo iconv_strlen($text, "UTF-8"), PHP_EOL; How It Works
- Use a word with an accent. The letter
éis 2 bytes. - strlen() counts bytes. So it returns 6.
- iconv_strlen() counts characters. So it returns 5.
- Pass the encoding. It is safer than the default.

