PHP 8 reference · 10 entries
PHP Multibyte String Functions
The mb_* functions for UTF-8 text: mb_strlen(), mb_substr(), mb_strtolower(), mb_str_pad(), mb_trim() and more, counting characters instead of bytes.
The mb_* functions come from the mbstring extension, which is enabled in almost every PHP install. They
count and cut by characters, so accented letters and non-Latin scripts work correctly. The encoding defaults to
UTF-8.
| Name | Description | Since |
|---|---|---|
mb_strlen() |
Return the number of characters in a string, counting é or 日 as one character. The UTF-8-safe version of strlen(). | 4.0 |
mb_substr() |
Return part of a string by character position, so multibyte characters are never cut in half. The UTF-8 version of substr(). | 4.0 |
mb_strtolower() |
Convert a string to lowercase, including letters outside ASCII such as É, Ü and Cyrillic. The Unicode-aware strtolower(). | 4.3 |
mb_strtoupper() |
Convert a string to uppercase, including letters outside ASCII such as é, ß and Cyrillic. The Unicode-aware strtoupper(). | 4.3 |
mb_convert_case() |
Change the case of a string with Unicode rules: upper, lower, title case or case folding for comparisons. | 4.3 |
mb_strpos() |
Find the character position of the first occurrence of a substring in a multibyte string. Returns false if not found. | 4.0 |
mb_str_split() |
Split a multibyte string into an array of characters, or of chunks of n characters. The UTF-8-safe str_split(). | 7.4 |
mb_str_pad() |
Pad a multibyte string to a given length in characters, on the left, right or both sides. Added in PHP 8.3. | 8.3 |
mb_trim() |
Strip whitespace from both ends of a string, including Unicode spaces such as the non-breaking space. Added in PHP 8.4. | 8.4 |
mb_ucfirst() |
Make the first character of a string title case, including letters such as é or ı. Added in PHP 8.4. | 8.4 |