In PHP, you can use the trim() function to remove spaces around a value. This function is used to remove whitespace characters or other predefined characters on both sides of a string. The syntax is "trim(string,charlist) ".
The operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer
trim() function removes whitespace characters or other predefined characters on both sides of a string.
Related functions:
ltrim() - Removes whitespace characters or other predefined characters on the left side of a string.
rtrim() - Removes whitespace characters or other predefined characters on the right side of a string.
Syntax
trim(string,charlist)
Parameter Description
string Required. Specifies the string to check.
charlist Optional. Specifies which characters are removed from a string. If this parameter is omitted, all the following characters are removed:
"\0" - NULL
"\t" - tab character
"\n" - Line feed
"\x0B" - Vertical tab character
"\r" - Enter
" " - Space
The example is as follows:
<?php $str = " 123456789 "; var_dump($str); echo "<br>"; var_dump(trim($str)); ?>
Output result:
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to remove spaces around values in php. For more information, please follow other related articles on the PHP Chinese website!