Home > Backend Development > PHP Problem > How to remove leading 0 in php

How to remove leading 0 in php

藏色散人
Release: 2023-03-12 21:34:01
Original
2080 people have browsed it

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

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!

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