Table of contents Home page
mb_internal_encoding('UTF-8'); $x = 'über'; echo "The string '$x' contains " . mb_strlen($x) . " characters.\n";
mb_internal_encoding('UTF-8'); $x = "\xfcber"; // String encoded in ISO-8859-1 echo mb_convert_encoding("The string '$x' contains '" . mb_strlen($x, 'ISO-8859-1'), 'UTF-8', 'ISO-8859-1') . " characters.\n"; // Because we've explicitly specified the encoding used for the string (ISO-8859-1), which is different from the // internal encoding (UTF-8), mb_strlen() still returns the correct number of characters. // Note that we assume that the output must be send in UTF-8, so we convert the string from // ISO-8859-1 to UTF-8, using mb_convert_encoding(), in order to have it displayed correctly.