Home > Article > Backend Development > How to remove the leading 0 in php
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.
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!