Table of contents Home page
mb_internal_encoding('UTF-8'); echo mb_substr('élite', 3), "\n"; // Return the part of the characters starting at position 3 (first one is 0!) echo mb_substr('élite', -3), "\n"; // Return the last 3 characters.
mb_internal_encoding('UTF-8'); echo mb_substr('élite', 3, 1), "\n"; // Return the character at position 3 (first one is 0!) echo mb_substr('élite', -3, 1), "\n"; // Return the third character from the right (rightmost one is 1!)
mb_internal_encoding('UTF-8'); $x = "\xdcber"; // String encoded in ISO-8859-1 echo mb_substr($x, 2, mb_strlen($x), 'ISO-8859-1'), "\n"; // Return the part of the characters starting at position 2 (first one is 0!) echo mb_substr($x, -3, mb_strlen($x), 'ISO-8859-1'), "\n"; // Return the last 3 characters. // Because we've explicitly specified the encoding used for the string (ISO-8859-1), which is different from the // internal encoding (UTF-8), mb_substr() still uses the correct character positions.