Home >Backend Development >PHP Problem >How to remove 0 in front of numbers in php
php method to remove the 0 in front of the number: 1. Remove the 0 in front of the number through the "str_replace ("0", "", $str);" method; 2. Through "preg_replace('/^0 */', '', $string);" method removes the 0 in front of the number.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
How to remove the 0 in front of the number in php?
When 01 is entered, only 1 is taken, no 0
Method one:
$str = '01'; $str = str_replace ("0", "", $str);
Method two:
echo preg_replace('/^0*/', '', $string);
Note: Learn PHP regular expressions carefully As follows:
ereg( "^[A-Za-z0-9_.-] $ ",$str);
eregi( "^[a-z0-9_.-] $ ",$str);
is_float: Determine whether the variable type is a floating point number type.
is_int: Determine whether the variable type is an integer type.
is_integer: Determine whether the variable type is a long integer type.
is_long: Determine whether the variable type is a long integer type.
is_object: Determine whether the variable type is an object type.
is_real: Determine whether the variable type is a real number type.
ereg -- Regular expression matching.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to remove 0 in front of numbers in php. For more information, please follow other related articles on the PHP Chinese website!