International PHP Conference Munich 2025

Voting

: min(two, five)?
(Example: nine)

The Note You're Voting On

anonymous at start dot be
20 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