Open In App

PHP mb_strcut() Function

Last Updated : 07 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The mb_strcut() is an inbuilt function in PHP that returns a portion of a multi-byte string based on a specified length and starting position.

Syntax:

mb_strcut( $string, $start, $length $encoding ): string

Parameters: This function takes four parameters that are described below.

  • $string: The multi-byte string to extract a portion from.
  • $start: The zero-based index at which to start the extraction.
  • $length: The maximum number of characters to extract. If not provided or set to null, the function extracts all characters from the starting position to the end of the string.
  • $encoding: The character encoding of the string. If not provided, internal encoding is used.

Return Value: The mb_strcut() function returns the string which is specified by the start and length parameters.

Example 1: The following program demonstrates the mb_strcut() function.

PHP




<?php
$str = "Hello, world!";
$portion = mb_strcut($str, 7);
echo $portion;
?>


Output:

world!  

Example 2: The following program demonstrates the mb_strcut() function.

PHP




<?php
$str = "Geeks for Geeks";
$portion = mb_strcut($str,5, 7);
echo $portion;
?>


Output:

 for Ge  

Reference: https://www.php.net/manual/en/function.mb-strcut.php


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads