... because of my ISP is blacklisted on two anti-spam-lists. So I'm going to post it here:

In some situations you need intval() to secure, e.g. id numbers:


So far with intval() you won't get any trouble:
$foo = intval($_GET['foo']);
print 'foo=' . $foo;

But when 'bar' grows larger than the number range of int, you got the wrong number back from intval(). This is not a fault in intval(), more the to small data type which int is.

Unfortunately there is no longval() or so. I came up with a regular expression solution to work-around this:
function bigintval ($str) {
$num = preg_replace('/[^0-9]*/', '', $str);
return $num;
This will replace all non-numeric characters with an empty string and therefore only characters of 0 to 9 (all numeric) will remain.

Hope this can help someone.
News-Flash: - Bitte den Bug-Tracker mehr nutzen! - Wiki verfuegbar - Bitte die neuste GIT-Revision von dieser Anleitung - Topic 180 herunterladen - Bug-Rallye gestartet! - Historisches Archiv angelegt - SVN-Howto - Commit-Statistik Feb 2008 - dato
« Last edit by Quix0r on Wed Aug 10, 2011 10:00 pm. »