The mb_strimwidth() function in PHP is used to truncate a given string with specified width. It is used to cut out the specified width from a given string.
Syntax
string mb_strimwidth($str_string, $int_start, $int_width, $str_trim_marker, $str_encoding)
For example,
mb_strimwidth($str_string: "PHP Tutorials", $int_start: 2, $int_width: 10, $str_trim_marker: "...",);
Parameters
mb_strimwidth() accepts five different parameters to trim the string width.
$str_string − The string that is to be decoded.
$int_start − This integer parameter will trim the string from the specified start position. It will trim the string of characters from the beginning of the string.
$int_width − The width of the desired trim. Negative widths count from the end of the string.
$str_trim_marker − It is a string that is added to the end of the given string when the string is cut/truncated.
$str_encoding − This is the character encoding parameter. If it is omitted or NULL, then the internal encoding value will be used.
Return Values
mb_strimwidth() returns the truncated string. If we set the trim_marker, then it will replace the last characters to match the width.
Example
<?php // UTF-8 encoding mb_internal_encoding("UTF-8"); // It will trim the given string width $str_string = mb_strimwidth("Simply Easy Learning!", 2, 15, "..."); // shows the resultant output echo "$str_string"; ?>
Output
It will produce the following output −
mply Easy Le...
Note − The above PHP code will start trimming the string from the 2nd character up to the 12th character. It uses internal encoding.