ConFoo Montreal 2026: Call for Papers

Voting

: max(five, three)?
(Example: nine)

The Note You're Voting On

anonymous at start dot be
21 years ago
Easier-to-grasp-function for the ',' problem.

<?php
function Getfloat($str) {
if(
strstr($str, ",")) {
$str = str_replace(".", "", $str); // replace dots (thousand seps) with blancs
$str = str_replace(",", ".", $str); // replace ',' with '.'
}

if(
preg_match("#([0-9\.]+)#", $str, $match)) { // search for number that may contain '.'
return floatval($match[0]);
} else {
return
floatval($str); // take some last chances with floatval
}
}

echo
Getfloat("$ 19.332,35-"); // will print: 19332.35
?>

<< Back to user notes page

To Top