note 27777 added to function.floatval
| From: | rainwolf76 at hotmail dot com | Date: | Wed, 18 Dec 2002 14:59:08 +0000 |
| Subject: | note 27777 added to function.floatval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-41065@lists.php.net to get a copy of this message | ||
"nik at orfanos dot org"'s floatval function for those of us not running 4.2+ did
help me, but to make sure it's fool proof you may want to use this instead:
function floatval( $strValue )
{
$floatValue = preg_replace( "/[^0-9\.]*/", "", $strValue );
if (false == is_numeric($floatValue)) $floatValue = 0;
return $floatValue;
}
(the if line just makes sure to return 0 incase there are no characters left after teh preg_replace,
or incase $strValue is something like 3.4.5.6)
- Patrick
--
http://www.php.net/manual/en/function.floatval.php
http://master.php.net/manage/user-notes.php?action=edit+27777
http://master.php.net/manage/user-notes.php?action=delete+27777
http://master.php.net/manage/user-notes.php?action=reject+27777