note 27777 deleted from function.floatval by sniper
| From: | sniper@php.net | Date: | Sat, 23 Aug 2003 00:16:31 +0000 |
| Subject: | note 27777 deleted from function.floatval by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-54903@lists.php.net to get a copy of this message | ||
Note Submitter: rainwolf76@hotmail.com
----
"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