Open In App

PHP mb_strimwidth() Function

The mb_strimwidth() function is an inbuilt function in PHP that returns the truncated string for the specified width.

Syntax:



string mb_strimwidth($string, $start, $width, $trim_marker, $encoding )

Parameters: This function accepts five parameters that are described below:

Return Values: This function returns the truncated string.



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




<?php
  
$str = "This is a very long string that needs to be trimmed";
$trimmed_str = mb_strimwidth($str, 0, 20, "...");
echo $trimmed_str;
  
?>

Output:

This is a very lo...  

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




<?php
  
$str = "Geeks for Geeks Matter";
$trimmed_str = mb_strimwidth($str, -5,5 , "Gee");
echo $trimmed_str;
  
?>

Output:

atter 

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

Article Tags :