YouTip LogoYouTip

Func String Trim

## PHP trim() Function **trim()** function removes whitespace or other predefined characters from both ends of the string. Related functions: * [ltrim()]( * [rtrim()]( ### Syntax ``` trim(string,charlist) ``` | Parameter | Description | | :--- | :--- | | string | Required. Specifies the string to check | | charlist | Optional. Specifies which characters to remove from the string. If omitted, the following characters will be removed: * " " - Ordinary space * "t" - Tab * "n" - Newline * "r" - Carriage return * "" - NUL-byte * "x0B" - Vertical tab | ### Technical Details | Return Value: | Returns the trimmed string | | :--- | :--- | | PHP Version: | 4+ | ### More Examples **Example 1** ```php <?php $str = "Hello World!"; echo $str . "
"; echo trim($str,"Hed!"); ?> ``` The output of the code above will be: ``` Hello World! llo World ```
← Func String UcfirstFunc String Substr Replace β†’