Skip to content

Trimming a string

Delete characters: trim()

With trim() function you can delete one or more characters from the beginning and end of a string.

Usually, the trim() function is intended as stripping blank space, in this case you can delete any characters.

echo trim("*_***___TEST_*______________", "*_") . PHP_EOL;
// result: TEST

The second parameter, you can list the characters that you want to eliminate.