PHP trim () Function

 A trim functions is used for remove character from both side of the strings

trim(string, charlist) 

String is your variable or your string parameter which specifies which you wants check

charlist parameter is optional it remove character from current sting

<?php
$str = "This is the simple text!";
echo trim($str,"This!");
?>

OUTPUT

is the simple text

You can also remove whole whitespace using trim function

<?php 
// PHP program to demonstrate the use of trim()  
// function when second parameter is absent 
  
$str = "  my dummy text "; 
  
// removes all leading and trailing whitespaces  
echo trim($str); 
?> 

OUTPUT

my dummy text

Above is example of the trim function

I hope this article will help you 🙂

Blog Catagory : PHP