Home >Backend Development >PHP Problem >How to remove 0 in front of numbers in php

How to remove 0 in front of numbers in php

藏色散人
藏色散人Original
2021-06-11 09:11:124490browse

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.

How to remove 0 in front of numbers in php

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!

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