note 123455 added to function.is-numeric
| From: | Ray.PaseursometimesusesGmail@php.net | Date: | Wed, 19 Dec 2018 20:50:45 +0000 |
| Subject: | note 123455 added to function.is-numeric | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209924@lists.php.net to get a copy of this message | ||
intval() appears to be helpful with hex strings:
<?php // is_hex_numeric.php
/**
* PHP 7.0.0+ Strings in hexadecimal (e.g. 0xf4c3b00c) notation
* are no longer regarded as numeric strings, i.e. is_numeric() returns FALSE now.
* See: http://php.net/manual/en/function.intval.php
*/
error_reporting(E_ALL);
var_dump( PHP_VERSION ); // string(6) "7.1.25"
var_dump( PHP_INT_SIZE ); // int(8)
$x = 0xf4c3b00c; // --> Assignment of hex value
var_dump($x); // int(4106465292)
var_dump( is_numeric($x) ); // bool(true)
$y = '0x' . dechex($x); // --> Convert hex value to a string
var_dump($y); // string(10) "0xf4c3b00c"
var_dump( is_numeric($y) ); // bool(false)
$z = intval($y, 0); // --> intval() with base zero recognizes hex notation
var_dump($z); // int(4106465292)
var_dump( is_numeric($z) ); // bool(true)
var_dump($x == $z); // bool(true)
----
Server IP: 208.43.231.9
Probable Submitter: 2600:8806:6400:36:8943:f0be:c00d:86ab
----
Manual Page -- http://php.net/manual/en/function.is-numeric.php
Edit -- https://master.php.net/note/edit/123455
Del: integrated -- https://master.php.net/note/delete/123455/integrated
Del: useless -- https://master.php.net/note/delete/123455/useless
Del: bad code -- https://master.php.net/note/delete/123455/bad+code
Del: spam -- https://master.php.net/note/delete/123455/spam
Del: non-english -- https://master.php.net/note/delete/123455/non-english
Del: in docs -- https://master.php.net/note/delete/123455/in+docs
Del: other reasons-- https://master.php.net/note/delete/123455
Reject -- https://master.php.net/note/reject/123455
Search -- https://master.php.net/manage/user-notes.php