Search code examples
phpgmp

PHP GMP: convert string to number ( change base )


In GMP extension in PHP it is possible to convert a large number to string. For example:

gmp_strval("1234999999999999999999999999999999213123123999999", 36);

gives:

p9owzsy9oqh5k9wdw0ve3si9futy5fj

Question: how to perform inverse transformation - make 1234999999999999999999999999999999213123123999999 out of p9owzsy9oqh5k9wdw0ve3si9futy5fj ?

Thank you.


Solution

  • The gmp_init() function takes an optional base argument.

    gmp_init('p9owzsy9oqh5k9wdw0ve3si9futy5fj', 36)