I need to know how many characters / numbers are in a number. Some of the numbers will have leading Zeros. After much reading I understand that if it has leading zeroes PHP translates this into an octal number. But I need a way to void that and treat the number as a normal number. also I need to be able to print this to the screen with the leading zeros later.
Is there any straight forward work around for this?
I dont want the octal number. I want it to know is 00123 or at least 123 Not 83.
Idealy my desired output is 3
or 5
when counting the characters in the number. and is a number not a string to begin with
$a = 00123;
echo $a; // Returns 83
echo strlen((string)$a); // Returns 2
echo mb_strlen($a, "UTF-8"); //Returns 2
$b = "". 00123 ."";
echo strlen((string)$b); //Returns 2
echo strlen(strval($b)); //Returns 2
You can use a combination of decoct and str_pad, like so. http://3v4l.org/TQgOq
You may want to sanity check some of the incoming values though.