PHP trim() Function


The trim() function is used to removes whitespace and other predefined characters from right and left sides of a string.

Syntax
trim(string,charlist)
Parameters
  • String - (Required) Specify the string to check.
  • charlist -(optional) Specify the characters to remove the string
    "\0" - NULL
    "\t" - tab
    "\n" - new line
    "\x0B" - vertical tab
    "\r" - carriage return
    " " - ordinary white space
Example
<?php
  $a = "Good Morning!";
  echo $a . "<br>";
  echo trim($a,"Gng!");
?>

Output

Good Morning!
ood Morni

Prev Next