Forum Moderators: coopster
It is only a short piece of code.
<html>
<body>
<form>
<label>Date: </label>
<select>
<?php
while ($a < 100) {
$a++;
$a2 = mktime(1, 1, 1, 1, $a, 2005);
$a3 = date(S,$a2);
echo <<<HTML
<option value="$a">$a$a3</option>
HTML;
}
?>
</select>
</form>
</body>
</html>
Let me know what you see for numbers in the drop-down menu over 31. Do they have the correct suffix or not? I am seeing incorrect suffixes used for numbers over 31.
Why use numbers later than 31? Because they might be useful for database text such as streets. So instead of "42nd Street" you could just store "42". But PHP is unable to add the correct suffix.
I checked the string functions instead of date/time but couldn't find anything in there. If anyone knows of a way round this problem, let me know! Otherwise I will file a bug report.
It's pretty nifty, you can run files right off your computer (as it turns your box in to an actual server) and configuartion is minimal. I especially enjoy the XAMPP control which can be minimized to the tray and run in the background as a single proccess.
Oh and yeah, it uses PHP (5.05 if I'm correct).
Let me know how it works out for yah...
John
Back to your question though, there is nothing PHP5-specific about your code there, why do you want to test it on PHP5? You haven't initialized your $a variable with anything for starters there ...
Make sense? Try this, you'll see exactly what I mean:
<?php
$a = 0;
$list = '';
while ($a < 100) {
$a++;
$a2 = mktime(1, 1, 1, 1, $a, 2005);
$a3 = date('jS',$a2);
$list .= <<<HTML
<option value="$a">$a3</option>
HTML;
}
?>
<html>
<body>
<form>
<label>Date: </label>
<select><?php print $list;?></select>
</form>
</body>
</html>
You can run your own web server, database server, etc. on any version of Windows, including XP Home version.
You mean Microsoft have conned me all these years? I honestly thought only XP Professional could run as a server! I'm sure certain programs won't run on Home...
Back to your question though, there is nothing PHP5-specific about your code there, why do you want to test it on PHP5?
Well... because the PHP bug report screen only lists the latest versions of 4 and 5. If you try and get round this it refuses to accept the bug report, saying to upgrade first. Since I am unable to do this right now, I just wondered if the 'bug' had been fixed in later versions. OK, so perhaps in hindsight it's not really a bug!
So how do I go about solving the problem then? How to add the correct suffix for numbers after 31? Or can it not be done?
Maybe it should be a feature request.
Back to your issue though, ...
So how do I go about solving the problem then? How to add the correct suffix for numbers after 31? Or can it not be done?
Sure, it can be done, but not using dates like you are trying to. Have a closer look at the code I posted and you'll see what is happening. If you just want to use English ordinal suffixes on a number range you'll have to use a different solution as opposed to running it through the date() function. Is this what you are really after?
Sure, it can be done, but not using dates like you are trying to... you'll have to use a different solution as opposed to running it through the date() function. Is this what you are really after?
Exactly. If I can't use dates, how can it be done? If it's a lenghty function, forget it. I was just after a ready-made solution from within PHP.
function getEnglishOrdinalSuffix($n)
{
$nn = $n % 100;
if ($nn > 3 && $nn < 21) {
return $n . 'th';
}
switch ($nn % 10) {
case '1': return $n . 'st';
case '2': return $n . 'nd';
case '3': return $n . 'rd';
default: return $n . 'th';
}
}
$list = '';
for ($n = 1; $n < 150; $n++) {
$list .= "$n: " . getEnglishOrdinalSuffix($n) . "\n";
}
print "<pre>$list</pre>";