There's nothing wrong with Java, it's structurally a much better language than PHP, I don't like weakly-typed languages for exactly the sort of reasons you mentioned. Unfortunately, loads of web hosts have PHP enabled, whereas comparatively few are set up to handle Java servlets.
Besides that, Java is generally considered overkill for the sort of basic text handling we're discussing here. Of course, the flip side of this is that most people end up using PHP for quite complicated data handling websites as well and then get in a mess, whereas using Java would have protected them from their mistakes a lot more. Personally I prefer C++, but that's a rant for another day, and you'd have to be a bit mad to do your server-side web processing in C++ anyway!
I don't see the problem with $original_num for internal processing vs. $ordinal_num for output to the HTML page, as you ought to be sanitising background data before outputting it to the page anyway — if you don't, you're inviting XSS attacks, not to mention all kinds of annoying HTML glitches with data that contains quotes, apostrophes, ampersands, etc...
As for the problem with non-integer numbers, a quick and dirty way to deal with it would be a cast to int of the input variable — not ideal, but then this function shouldn't be called on non-int variables anyway! If you want to do it the proper way and protect users from themselves(!), you could add a conditional based on PHP's is_int() function. If it's false, just return the input variable unchanged...
There's nothing wrong with Java, it's structurally a much better language than PHP, I don't like weakly-typed languages for exactly the sort of reasons you mentioned. Unfortunately, loads of web hosts have PHP enabled, whereas comparatively few are set up to handle Java servlets.
Besides that, Java is generally considered overkill for the sort of basic text handling we're discussing here. Of course, the flip side of this is that most people end up using PHP for quite complicated data handling websites as well and then get in a mess, whereas using Java would have protected them from their mistakes a lot more. Personally I prefer C++, but that's a rant for another day, and you'd have to be a bit mad to do your server-side web processing in C++ anyway!
I don't see the problem with
$original_numfor internal processing vs.$ordinal_numfor output to the HTML page, as you ought to be sanitising background data before outputting it to the page anyway — if you don't, you're inviting XSS attacks, not to mention all kinds of annoying HTML glitches with data that contains quotes, apostrophes, ampersands, etc...As for the problem with non-integer numbers, a quick and dirty way to deal with it would be a cast to int of the input variable — not ideal, but then this function shouldn't be called on non-int variables anyway! If you want to do it the proper way and protect users from themselves(!), you could add a conditional based on PHP's
is_int()function. If it's false, just return the input variable unchanged...