PHP code displaying character instead of number
Posted: Wed May 28, 2014 2:09 pm
I have been bedeviled by this problem periodically. I have PHP code that generates a number and stores it in a variable, but when I display the variable on a web page, SOMETIMES it is displayed as an odd character instead instead of the number. The current example is that I have generated the value of 10, but it displays as a colon on the web page. The behavior is browser specific - the current example happens with Chrome & IE, but not with Firefox.
The application is displaying hours worked and leave accrual information based on a database of submitted time reports. There is a method that calculates how much vacation was earned based on employee hire date and hours worked and another that calculates what the maximum vacation accrual for the employee is. Here is the relevant code:
I can usually find a kludge to fix this by echoing the variable to the page once first and then doing it for real. The lines that display the value look like this:
[text]
<!-- the following line is my kludge to get around the problem -->
<!-- <?php echo $vacEarned; ?> -->
<td class="formField" align="center"><?php echo $vacEarned; ?><?php echo ($maxedVac ? " *" : ""); ?></td>
[/text]
(Note that the code prints an asterisk next to the value if the accrual has maxed out - not the case in this example) Any suggestions?
The application is displaying hours worked and leave accrual information based on a database of submitted time reports. There is a method that calculates how much vacation was earned based on employee hire date and hours worked and another that calculates what the maximum vacation accrual for the employee is. Here is the relevant code:
Code: Select all
// $rates - the current monthly accrual rates, based on years of service
// $allocRatio - the ratio of hours worked to the monthly number of hours, for vacation allocation purposes
// $yos - years of service
function vacEarned($rates, $allocRatio, $yos) {
$rate = $rates['vacation5'];
if ($yos>=15)
$rate = $rates['vacation20'];
else if ($yos>=10)
$rate = $rates['vacation15'];
else if ($yos>=5)
$rate = $rates['vacation10'];
return round($allocRatio * $rate, 2);
}
...
$maxedVac = false;
...
$maxVac = maxVacation($currentRates, $hireDate, $tlrDates[$dateID], $currentPctTime);
$vacEarned = vacEarned($currentRates, $allocRatio, $yos);
$vacUsed = $usage[$idx]['vacUsed'];
$currentVac += $vacEarned - $vacUsed;
if ($currentVac>$maxVac) {
$maxedVac = true;
$vacEarned = $vacEarned + $maxVac - $currentVac;
$currentVac = $maxVac;
}I can usually find a kludge to fix this by echoing the variable to the page once first and then doing it for real. The lines that display the value look like this:
[text]
<!-- the following line is my kludge to get around the problem -->
<!-- <?php echo $vacEarned; ?> -->
<td class="formField" align="center"><?php echo $vacEarned; ?><?php echo ($maxedVac ? " *" : ""); ?></td>
[/text]
(Note that the code prints an asterisk next to the value if the accrual has maxed out - not the case in this example) Any suggestions?