PHP : Convert(cast) string to bigInt
Problem :
In PHP, you want to convert(cast) a string to become big integer value.
Solution :
Use GNU Multiple Precision's gmp_intval() function to convert the string to a big integer value.
For example :
<?php
$str = "123456789123456789";
$bigInt = gmp_init($str);
$bigIntVal = gmp_intval($bigInt);
echo $bigIntVal."\n";
?>
Output :
123456789123456789
Notes :
See http://php.net/manual/en/gmp.installation.php on how to get GMP installed on your server.
Reference :
See also : PHP : Convert(cast) bigInt to string
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+23.2k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+5.4k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+15.6k Golang : Update database with GORM example
+10.9k Golang : Fix - does not implement sort.Interface (missing Len method)
+25.5k Golang : How to read integer value from standard input ?
+11.6k Golang : Setup API server or gateway with Caddy and http.ListenAndServe() function example
+19k Mac OSX : Homebrew and Golang
+8.6k Golang : Get final balance from bit coin address example
+16.2k Golang : How to implement two-factor authentication?
+6.6k Default cipher that OpenSSL used to encrypt a PEM file
+25.1k Golang : Daemonizing a simple web server process example
+14.2k Golang : How to check if your program is running in a terminal