mb_trim()

mb_trim() — Strip whitespace (or other characters) from the beginning and end of a string.

Built-in function of PHP 8.5. The manual lists it as available in PHP 8 >= 8.4.0. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

mb_trim(string $string, ?string $characters = null, ?string $encoding = null): string

Parameters

ParameterTypeWhat it takes
$stringstringThe string that will be trimmed.
$characters?stringOptionally, the stripped characters can also be specified using the characters parameter. Simply list all characters that need to be stripped.
$encoding?stringThe encoding parameter is the character encoding. If it is omitted or null, the internal character encoding value will be used.

Return value

The trimmed string.

Example

The PHP manual ships no example for mb_trim(); the signature and the parameter table above are the contract.

See also

mb_ltrim(), mb_rtrim(), trim()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page mb_trim() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.