PHP — Convert string to bigint

前端 未结 5 1485
眼角桃花
眼角桃花 2021-01-14 10:34

I have the following string which i need to convert to integer or bigint.

$test=\"99999977706\";

I tried:

echo (int)$test;
         


        
相关标签:
5条回答
  • 2021-01-14 10:56

    For arbitrary length integers use GMP.

    0 讨论(0)
  • 2021-01-14 11:04

    In your snippet $test is already a number, more specifically a float. PHP will convert the contents of $test to the correct type when you use it as a number or a string, because the language is loosely typed.

    0 讨论(0)
  • 2021-01-14 11:07

    MySQL isn't going to know the difference. Just feed the string into your query as though it is a number without first type casting it in PHP.

    For example:

    $SQL = "SELECT * FROM table WHERE id = $test";
    
    0 讨论(0)
  • 2021-01-14 11:17

    working solution :

    <?php
       $str = "99999977706";
       $bigInt = gmp_init($str);
       $bigIntVal = gmp_intval($bigInt);
       echo $bigIntVal;
       ?>
    

    It will return : 99999977706

    0 讨论(0)
  • 2021-01-14 11:18

    It can help you,

    $token=  sprintf("%.0f",$appdata['access_token'] );
    

    you can refer with this link

    0 讨论(0)
提交回复
热议问题