PHP function trim()

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

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

Newsletter

Nejlepsi tipy a triky o PHP do Vaseho e-mailu. Clanky a novinky nejen ze sveta PHP a programovani.