PHP – mb_strcut() function

PHPServer Side ProgrammingProgramming

The mb_strcut() function in PHP is used to get a part of a specified string. It extracts the substring from a given string. It operates on bytes instead of characters. If the cut position happens to be between two bytes of multi-byte characters, then the cut is achieved starting from the first byte of those characters.


string mb_strcut(

For example:

   int= 6,
   encoding= "UTF-8"


mb_strcut() accepts the following four parameters −

  • str_string − The string parameter being cut.

  • int_start − If the start parameter is non-negative, then the returned string will start from the starting byte position in a given string, counting from zero. For example, in a string "onlinetutorial", the byte at position '0' is 'o', and the byte at position '1' is 'n' and so on. If the start is negative, then the given string will start counting back from the end of the string.

  • If the magnitude of the negative start is greater than the string length, then the returned portion will start extracting from the beginning of the string.

  • int_length − It returns the length in bytes. If the length is omitted, then NULL is passed, it extracts all the bytes up to the end of the string. If the given length is negative, then the returned string will end at the length byte containing back from the end of the string.

  • encoding − It is the character encoding parameter. If it is omitted or NULL, then the internal encoding value is used.

Return Values

mb_strcut() returns the specified portion of the string by the start and length parameters.


   //UTF-8 encoding
   //String online tutorial will cut the string from 6
   // to till 5 characters
   $string = mb_strcut("Onlinetutorial", 6, 5, "UTF-8");
   $str = mb_strtoupper($string);

   //output "TUTOR"


Updated on 12-Oct-2021 06:35:18