php method to remove leading 0: 1. Create a PHP sample file; 2. Use the "ltrim($str, '0');" method to remove the "0" on the left side of the string.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to remove leading 0 in php?
It is very simple to remove leading 0s, just use the ltrim function.
To remove leading 0s, just use the following code:
$str = ltrim($str, '0');
ltrim() function removes whitespace characters or other predefined characters on the left side of the string.
Parameters:
string required. Specifies the string to check.
charlist optional. Specifies which characters are removed from the string. If this parameter is omitted, all of the following characters are removed:
"\0" - NULL
"\t" - Tab
"\n" - Newline
"\x0B" - vertical tab
"\r" - carriage return
" " - space
Recommended learning: "PHP video tutorial》
The above is the detailed content of How to remove leading 0 in php. For more information, please follow other related articles on the PHP Chinese website!