Definition
The trim() function is used to remove whitespace and other predefined characters from both sides of a string.
Syntax
trim(string, charlist)
Parameters
Parameter | Description |
---|---|
string |
Required. Specifies the string to check. |
charlist |
Optional. Specifies which characters to remove from the string. If omitted, all of the following characters are removed:"\0" - null "\t" - tab"\n" - new line"\x0B" - vertical tab"\r" - carriage return" " - ordinary white space |
Example
<?php
$str = "Welcome to PHP!";
echo trim($str, "WP!");