note 89293 added to function.intval
| From: | jeromakay at yahoo dot com | Date: | Mon, 02 Mar 2009 10:40:11 +0000 |
| Subject: | note 89293 added to function.intval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151315@lists.php.net to get a copy of this message | ||
To convert a string to a number, and avoid the 32 bit issues of intval you can use:
<?php
$no = "214742780440" + 0;
var_dump($no); // float(214742780440)
?>
I used to intval() everything before entering it into the DB, but it seems impractical with values
over 2147483647.
To get even better idea of how it validates, try this:
<?php
$no = "qwerty1234" + 0;
var_dump($no); // int(0)
?>
----
Server IP: 212.108.64.191
Probable Submitter: 84.203.220.8
----
Manual Page -- http://www.php.net/manual/en/function.intval.php
Edit -- https://master.php.net/note/edit/89293
Del: integrated -- https://master.php.net/note/delete/89293/integrated
Del: useless -- https://master.php.net/note/delete/89293/useless
Del: bad code -- https://master.php.net/note/delete/89293/bad+code
Del: spam -- https://master.php.net/note/delete/89293/spam
Del: non-english -- https://master.php.net/note/delete/89293/non-english
Del: in docs -- https://master.php.net/note/delete/89293/in+docs
Del: other reasons-- https://master.php.net/note/delete/89293
Reject -- https://master.php.net/note/reject/89293
Search -- https://master.php.net/manage/user-notes.php