Most of the functions listed here that deal with $ and , are unnecessarily complicated. You can use ereg_replace() to strip out ALL of the characters that will cause floatval to fail in one simple line of code:

Use this snippet to extract any float out of a string. You can choose how a single dot is treated with the (bool) 'single_dot_as_decimal' directive.This function should be able to cover almost all floats that appear in an european environment.

<?php

function float($str, $set=FALSE) { if(preg_match("/([0-9\.,-]+)/", $str, $match)) {// Found number in $str, so set $str that number$str = $match[0];

floatval() does not work with "$35,234.43", as it could not handle the '$' and the ','. The following takes care of all values, such that only numeric and the decimal sign are input into floatval(). (It probably shows I'm an old 'c' guy)...this function only lightly tested.

i noticed all (well, unless i missed something) the functions working with decimals destroy trailing decimal places. this function restores them in case you want to be able to display a consistent precision for users.

This function converts a string to a float no matter is the decimal separator dot (.) or comma (,). It also converts integers correctly. It takes the digits from the beginning of the string and ignores all other characters.