Home > Backend Development > PHP Problem > 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

藏色散人
Release: 2023-03-01 07:08:01
Original
3558 people have browsed it

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, ",");
Copy after login

The result returned is:

a,b,c,d
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template