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

How to remove the leading 0 in php

藏色散人
Release: 2023-03-04 09:48:02
Original
4024 people have browsed it

php method to remove the previous 0: 1. Use the [$number 0;] method; 2. Use the [preg_replace('/^0 /','',$number);] method; 3. Use the [intval($number);] method.

How to remove the leading 0 in php

Recommended: "PHP Video Tutorial"

Specific questions:

How to remove the 0 in front of the number in php? When 01 is entered, only 1 is taken without 0

Implementation method:

$number = '0101.01';

Method 1:

echo $number+0;
Copy after login

Method 2:

echo preg_replace('/^0+/','',$number);
Copy after login

If $number = '0101'; only numbers are combined, you can also use the following methods

Method 3:

echo intval($number);
Copy after login

Method Four:

echo (int)$number;
Copy after login

The above is the detailed content of How to remove the 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