Sign in Registration

Multibyte encodings, why do we need functions with the mb prefix in PHP


Often, when developing a web application or site, it is necessary to work with text resources. As a rule, the text has its own encoding, so it is important to use the appropriate functions. Today the most popular encoding is UTF8, it is a multibyte encoding.

What does multibyte encoding mean? This means that more than one byte can be allocated per character. Indeed, all characters are represented by bytes, to encode a character, a certain number of them will be required, and one may not be enough. This is especially true for unusual symbols and letters of any languages. Therefore, multibyte encodings are needed, of course PHP supports them.

There are functions that can independently determine the encoding of the text. You can also specify the desired encoding in them, if necessary. There are some functions that begin with the mb_ prefix . They are specially designed to work with text, mb means multibyte .

Let's see what are the main mb functions in PHP , below are only the most used ones:

  • mb_convert_case - changes the case of characters in a line,
  • mb_convert_encoding - converts character encoding,
  • mb_detect_encoding - character encoding detection,
  • mb_internal_encoding - setting or getting the internal encoding of the script,
  • mb_ord - gets the character code point,
  • mb_split - splitting strings in multibyte encodings using a regular expression
  • mb_strcut - get part of a string,
  • mb_stripos - case-insensitive search for the position of the first occurrence of one string in another,
  • mb_strlen - gets the line length,
  • mb_strpos - search for the position of the first occurrence of one line in another,
  • mb_strripos - search for the last occurrence of one string in another, case insensitive
  • mb_strrpos - search for the position of the last occurrence of one line in another,
  • mb_strstr - finds the first occurrence of a substring in a string,
  • mb_strtolower - converting the string to lower case,
  • mb_strtoupper - converting a string to upper case,
  • mb_substr - Returns part of a string.

Thus, it is best to use multibyte encodings for working with text. They allow correct operations with symbols.

Comments (0)
For commenting sign in or register.

Latest articles

Popular sections

Eqsash (Tools)

Android app - VK LAST USER ID, отучитель от зависимости и т.д.:
Available on Google Play

Amessage (Communication)

Login to the web version
Android app:
Available on Google Play

Share this

Subscribe to



IT notes - In simple language about the most necessary things (HTML, CSS, JavaScript, PHP, databases, Drupal, Bitrix, SEO, domains, security and more), PDF, 500 p.