Gen. partnerAlgotech

PHP function trim()

Deletes whitespace (or other characters) from the beginning and end of a string.

|
September 11, 2019

Availability in PHP 4.0

Deletes whitespace (or other characters) from the beginning and end of a string.

Alternatively, use ltrim() (deletes from the left), or rtrim() (deletes from the right).

Parameters

Parameter Data type Default value Note
$str string not String to be truncated.
$charlist string " Optionally, trimmed characters can also be specified using the $charlist parameter. Simply specify all the characters you want to get rid of. Use the .. construct to specify a range of characters.

Return values

string

Modified string

echo trim(' Hi, how are you? '); // "Hi, how are you?"

Other resources

Official documentation of the trim function

Loading comments...

Stay in the loop

Subscribe to our newsletter and get the latest cybersecurity news delivered straight to your inbox.

Your data is safe. You can unsubscribe from the newsletter at any time.