Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php $str = 'Héllo Wörld'; // 11 characters, but >11 bytes in UTF-8 echo strlen($str); // e.g. 13 (bytes) echo mb_strlen($str); // 11 (characters) echo mb_strtoupper($str, 'UTF-8'); // HÉLLO WÖRLD echo mb_strtolower($str, 'UTF-8'); // héllo wörld echo mb_substr($str, 0, 5, 'UTF-8'); // Héllo // Safe check for multibyte position $pos = mb_strpos($str, 'Wö', 0, 'UTF-8'); echo $pos; // 6 // Convert encoding $latin = mb_convert_encoding($str, 'ISO-8859-1', 'UTF-8'); // Set internal encoding once at bootstrap mb_internal_encoding('UTF-8'); // After this, the encoding argument can be omitted echo mb_strlen($str); // 11
Result
Open