Home  >  Article  >  Backend Development  >  How to remove the first comma on the left side of a php string

How to remove the first comma on the left side of a php string

藏色散人
藏色散人Original
2020-05-10 13:08:353466browse

How to remove the first comma on the left side of a php string

How to remove the first comma on the left in a php string

Example:

$str = ",a,b,c,d";
echo ltrim($str, ",");

The result returned is:

a,b,c,d

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)

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn