Reputation: 15
I have php code
preg_replace( "/([0-9]{2})([0-9]{4})([0-9]{4})([0-9]{4})/",
"$1 $2 $3 $4",
121234123412341234)
The result of this is 1.21234123412E+17
. I need to be 12 1234 1234....
Maybe i need to use other function?
Upvotes: 0
Views: 110
Reputation: 146460
Use strings. PHP cannot handle such large integers unless they get converted to float:
The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18. PHP does not support unsigned integers. Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5.
In my computer, PHP_INT_MAX
is 2147483647.
To sum up, please compare:
var_dump(121234123412341234, '121234123412341234');
float(1.2123412341234E+17)
string(18) "121234123412341234"
Upvotes: 0
Reputation: 30488
Use single quote around input
echo preg_replace("/([0-9]{2})([0-9]{4})([0-9]{4})([0-9]{4})/", "$1 $2 $3 $4", '121234123412341234');
Output
12 1234 1234 12341234
Upvotes: 2