note 91649 modified in function.intval by danbrown

From: Date: Mon, 22 Jun 2009 12:51:50 +0000
Subject: note 91649 modified in function.intval by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157229@lists.php.net to get a copy of this message
Here is a really useful undocumented feature: You can have it automatically deduce the base of the number from the prefix of the string using the same syntax as integer literals in PHP ("0x" for hexadecimal, "0" for octal, non-"0" for decimal) by passing a base of 0 to intval(): <?php echo intval("0x1a", 0), "\n"; // hex; prints "26" echo intval("057", 0), "\n"; // octal; prints "47" echo intval("42", 0), "\n"; // decimal; prints "42" ?> --was-- Here is a really useful undocumented feature: You can have it automatically deduce the base of the number from the prefix of the string using the same syntax as integer literals in PHP ("0x" for hexadecimal, "0" for octal, non-"0" for decimal) by passing a base of 0 to intval(): echo intval("0x1a", 0), "\n"; // hex; prints "26" echo intval("057", 0), "\n"; // octal; prints "47" echo intval("42", 0), "\n"; // decimal; prints "42" http://php.net/manual/en/function.intval.php

« previous php.notes (#157229) next »