Home  >  Article  >  Backend Development  >  How to remove leading 0 in php

How to remove leading 0 in php

藏色散人
藏色散人Original
2021-09-24 09:48:472038browse

php method to remove leading 0: 1. Create a PHP sample file; 2. Use the "ltrim($str, '0');" method to remove the "0" on the left side of the string.

How to remove leading 0 in php

The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.

How to remove leading 0 in php?

It is very simple to remove leading 0s, just use the ltrim function.

To remove leading 0s, just use the following code:

$str = ltrim($str, '0');

ltrim() function removes whitespace characters or other predefined characters on the left side of the string.

Parameters:

string required. Specifies the string to check.

charlist optional. Specifies which characters are removed from the 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

Recommended learning: "PHP video tutorial

The above is the detailed content of How to remove leading 0 in php. 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