At 4:28 PM -0500 1/15/01, bill wrote:
>Sometimes clients put a dollar sign "$" in a form that only needs a
>number (like "1.50").
>
>Is there a way to take a post variable and automatically convert it to a
>float value, stripping off any non-numeric characters?
>
>I tried doubleval() without success and I can't use intval() because it
>has decimals.
>
>kind regards,
>
$SanitizedNumber = ereg_replace('[^0-9.]', '', $NumberString);
If you really need to make this a float variable, then you can add
$Number = (float)$SanitizedNumber;
although in most cases PHP handles type conversion correctly on-the-fly.
- steve
+--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg University of California, Davis |
| [EMAIL PROTECTED] Computer Consultant |
| http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ |
+-------------------------------------- FBI Special Agent Dale Cooper ---+
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]