PHP is a scripting language, but it's magical, you use the post a string of numbers to pass, with Var_dump () print out, you will find that the string number format is string.
Today, I'm going to do a function to put 12 digits, such as: 000000100000
Like the above to be divided into units of numbers, the average person looks very troublesome, so we have to deal with the display as follows
It's easier to look like this. How to deal with, I intended to use regular, but/d is to match the number of 0-9, I would like to write a new way of matching, repeated reflection, or with
The Simple Way
function Transamt ($value)
{
//convert string to array
$array = Str_split ($value);
Arrays are traversed by
foreach ($array as $key => $va)
{
if ($va!= 0)
{
$ start = $key;
Break
;
}
}
Splits the string group
$len = strlen ($value)-$start;
$substr = substr ($value, $start, $len);
To process the data, first get the length of the substring
$smallnum = substr ($substr, -2,2);
$bignum = substr ($substr, 0, $len-2);
Return $bignum. ". $smallnum;
}
This is done by converting the string into arrays and then manipulating the array.
This should be regarded as the idiom of PHP operation string.
The simplest way of programming: encountering problems, proposing solutions to problems, and summing up many problems, and getting common ground.
In general, the process-oriented function is transformed into an object-oriented class.