The source of pad_test.php (click to demo the file) viewed 1575 times.
If I wrote this code, then it is licensed under the GPL. If someone else wrote it, then please ask them if you want to use the code.
<?php
// Input number
$number = "1023";
echo "Input number: <b>$number</b><br>";
// Padding number to 6 digits
$number = str_pad($number, 6, "0", STR_PAD_LEFT);
echo "Number after padding to 6 digits: <b>$number</b><br>";
// Checking to see how many 0's there are at the start of the string
$zero_length = strspn($number, "0");
echo "Number of zeros found at the start of string: <b>$zero_length</b><br>";
// Removing the number of 0's at the start
$number = substr($number, $zero_length);
echo "Number after zero's removed: <b>$number</b>";
// Output
//
// Input number: 1023
// Number after padding to 6 digits: 001023
// Number of zeros found at the start of string: 2
// Number after zero's removed: 1023
?>
If you want to have a look at the source code, chose a file from this list:
To colour code your own PHP paste it here: