HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

mb_trim

Description

The mb_trim of Multibyte String for PHP strips whitespace (or other characters) from the beginning and end of a string.

Syntax

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

Parameters

string

The input string.

characters

The list of all the characters that need to be stripped.

encoding

The character encoding.

If omitted or null, the internal character encoding value will be used.

Return

Returns a string with whitespace stripped from the beginning and end of the string.

Examples

1 · string

<?

$string = "\0\t\n\v\r \x00\x09\x0A\x0B\x0D\x20🐘string\0\t\n\v\r \x00\x09\x0A\x0B\x0D\x20";

$return = mb_trim($string);

var_dump($string, $return);
string(34) "    

     

 🐘string    

     

 "
string(10) "🐘string"

2 · characters

<?

$string = "\0\t\n\v\r \x00\x09\x0A\x0B\x0D\x20🐘string\0\t\n\v\r \x00\x09\x0A\x0B\x0D\x20";
$characters = "\0\t\n\v\r 🐘sng";

$return = mb_trim($string, $characters);

var_dump($string, $return);
string(34) "    

     

 🐘string    

     

 "
string(3) "tri"

3 · encoding

<?

$string = "\0\t\n\v\r \x00\x09\x0A\x0B\x0D\x20🐘string\0\t\n\v\r \x00\x09\x0A\x0B\x0D\x20";
$characters = "\0\t\n\v\r 🐘sng";
$encoding = "UTF-8";

$return = mb_trim($string, $characters, $encoding);

var_dump($string, $return);
string(34) "    

     

 🐘string    

     

 "
string(3) "tri"