note 88041 modified in function.is-numeric by felipe
| From: | felipe@php.net | Date: | Sat, 17 Jan 2009 01:19:35 +0000 |
| Subject: | note 88041 modified in function.is-numeric by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149353@lists.php.net to get a copy of this message | ||
regarding the global vs. american numeral notations, it should be noted that at least in japanese,
numbers aren't grouped with an extra symbol every three digits, but rather every four digits
(for example 1,0000 instead of 10.000). also nadim's regexen are slightly suboptimal at one
point having an unescaped '.' operator, and the whole thing could easily be combined into
a single regex (speed and all).
adjustments:
<?php
$eng_or_world = preg_match
('/^[+-]?'. // start marker and sign prefix
'(((([0-9]+)|([0-9]{1,4}(,[0-9]{3,4})+)))?(\\.[0-9])?([0-9]*)|'. // american
'((([0-9]+)|([0-9]{1,4}(\\.[0-9]{3,4})+)))?(,[0-9])?([0-9]*))'. // world
'(e[0-9]+)?'. // exponent
'$/', // end marker
$str) == 1;
?>
i'm sure this still isn't optimal, but it should also cover japanese-style numerals and it
fixed a couple of other issues with the other regexen. it also allows for an exponent suffix, the
pre-decimal digits are optional and it enforces using either grouped or ungrouped integer parts.
should be easier to trim to your liking too.
--was--
regarding the global vs. american numeral notations, it should be noted that at least in japanese,
numbers aren't grouped with an extra symbol every three digits, but rather every four digits
(for example 1,0000 instead of 10.000). also nadim's regexen are slightly suboptimal at one
point having an unescaped '.' operator, and the whole thing could easily be combined into
a single regex (speed and all).
adjustments:
$eng_or_world = preg_match
('/^[+-]?'. // start marker and sign prefix
'(((([0-9]+)|([0-9]{1,4}(,[0-9]{3,4})+)))?(\\.[0-9])?([0-9]*)|'. // american
'((([0-9]+)|([0-9]{1,4}(\\.[0-9]{3,4})+)))?(,[0-9])?([0-9]*))'. // world
'(e[0-9]+)?'. // exponent
'$/', // end marker
$str) == 1;
i'm sure this still isn't optimal, but it should also cover japanese-style numerals and it
fixed a couple of other issues with the other regexen. it also allows for an exponent suffix, the
pre-decimal digits are optional and it enforces using either grouped or ungrouped integer parts.
should be easier to trim to your liking too.
http://php.net/manual/en/function.is-numeric.php