Forum Moderators: coopster
if([url=http://www.php.net/manual/en/function.substr-count.php]substr_count[/url]($price,'.') > 1) {
echo 'Error - too many periods!';
} else {
echo 'Good price - proceed.';
}
$inputValue = '99.9999.9.999.99'; // -> input here..
$explodedValue = explode(".", $inputValue); // -> explode the value, separator would be the point
$countValueOfPeriod = sizeof($explodedValue); // -> count the array
$limit = $countValueOfPeriod - 1; // -> get the last number for the array element
if ($countValueOfPeriod > 2) // -> check if the array has a lot of periods
{
$lastValue = $countValueOfPeriod - 1;
$PeriodPlacement = $countValueOfPeriod - 2;
echo $countValueOfPeriod . "<br>";
for ($i = 0; $i <= $limit; $i++)
{
if ($i == 0)
{
$newValue .= $explodedValue[$i] . ',';
}
else
{
if ($i == $PeriodPlacement)
{
$newValue .= $explodedValue[$i] . '.';
} else {
if ($i!= $lastValue)
{
$newValue .= $explodedValue[$i] . ',';
}
else
{
$newValue .= $explodedValue[$i];
}
}
}
}
} else {
$newValue = $inputValue;
}
echo $newValue;
?>