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

How to remove the leading 0 in php

藏色散人
藏色散人Original
2020-08-11 11:06:563960browse

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;

Method 2:

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

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

Method 3:

echo intval($number);

Method Four:

echo (int)$number;

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!

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