Home > Article > Backend Development > What are the functions in php that can remove spaces?
The functions in php that can remove spaces are: 1. ltrim(), this function can remove spaces at the beginning of a string; 2. rtrim(), this function can remove spaces at the end of a string; 3. , trim(), this function can remove spaces at the beginning and end of a string.
#ltrim function removes spaces or other characters at the beginning of a string.
(Recommended tutorial: php graphic tutorial)
Syntax:
string ltrim(string $str [,string $charlist])
Description: charlist specifies which characters to delete from the string. If this parameter is omitted by default, all the following characters
are removed. Example:
$str = "\n\n\t\tABC\t\t"; echo ltrim($str); //输出后,ABC前面的空白就没有了
rtrim function removes spaces or other characters at the end of a string.
(Video tutorial recommendation: php video tutorial)
Syntax:
string rtrim(string $str[,string $charlist])
trim function to delete spaces or other spaces at the beginning and end of a string character.
Grammar:
string trim(string $str[,string $charlist])
Example:
The above is the detailed content of What are the functions in php that can remove spaces?. For more information, please follow other related articles on the PHP Chinese website!