note 55240 added to function.is-numeric
| From: | sebu at osu1 dot php dot net | Date: | Thu, 28 Jul 2005 11:37:25 +0000 |
| Subject: | note 55240 added to function.is-numeric | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92626@lists.php.net to get a copy of this message | ||
Referring to previous post "Be aware if you use is_numeric() or is_float() after using
set_locale(LC_ALL,'lang') or set_locale(LC_NUMERIC,'lang')":
This is totally wrong!
This was the example code:
-----
set_locale(LC_NUMERIC,'fr');
is_numeric(12.25); // Return False
is_numeric(12,25); // Return True
is_float(12.25); //Return False
is_float(12,25); //Return True
-----
This is nonsense!
- set_locale() does not exist, you must use setlocale() instead
- you have to enclose 12,25 with quotes; otherwise PHP will think that
the function gets _two_ arguments: 12 and 25 (depending on PHP version and setup you may
additionally get a PHP warning)
- if you don't enclose 12,25 with quotes the first argument will be the inspected value (12),
the second value (25) is discarded. And is_numeric(12) and is_float(12) is always TRUE
Corrected Example:
----
setlocale(LC_NUMERIC,'fr');
is_numeric(12.25); // Return True
is_numeric("12,25"); // Return False
is_float(12.25); //Return True
is_float("12,25"); //Return False
----
Remarks:
- is_float(12.25) is _always_ TRUE, 12.25 is a PHP language construct (a "value") and the
way PHP interpretes files is definitely _not_ affected by the locale
- is_float("12,25") is _always_ FALSE, since is_float (other than is_numeric): if the
argument is a string then is_float() always returns FALSE since it does a strict check for floats
And the corrected example shows: you get the _same_ results for every possible locale, is_numeric()
does not depend on the locale.
----
Manual Page -- http://www.php.net/manual/en/function.is-numeric.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55240
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55240&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55240&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55240&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55240&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55240&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55240&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55240&report=yes
Search -- http://master.php.net/manage/user-notes.php