How to remove the first comma on the left in a php string
Example:
$str = ",a,b,c,d";
echo ltrim($str, ",");
Copy after login
The result returned is:
The function used is ltrim();
##ltrim() definition and usage
ltrim( ) function removes whitespace or other predefined characters from the left side of a string.
Syntax
ltrim(string,charlist)
Copy after login
Parameters
string Required. Specifies the string to check.
charlist Optional. Specifies which characters are removed from a string. If this parameter is omitted, all of the following characters are removed:
"\0" - NULL
"\t" - Tab
"\n" - Newline
"\x0B" - vertical tab
"\r" - carriage return
" " - space
Return value: Return modified String.
Related functions:
rtrim() - Removes whitespace characters or other predefined characters on the right side of the string.
trim() - Removes whitespace or other predefined characters from either side of a string.
Recommended: "
PHP Video Tutorial"
The above is the detailed content of How to remove the first comma on the left side of a php string. For more information, please follow other related articles on the PHP Chinese website!