PHP code to add st, nd, rd or th to a number
This one's short and sweet: while working on a PHP application I needed to format some numbers as text so that, for example, '1' became '1st', '13' became '13th', '22' became '22nd' and so on. There isn't a built-in PHP function to do this (as far as I know) and none of the code snippets I came across online were very neat, so I ended up writing my own function. Since it's something that I imagine gets used a lot, I thought I'd put it up here.