If you're working with dates, use "date()", otherwise this will work:
function num_suffix($num)
{
$suffix_arr = array('th', 'st', 'nd', 'rd');
$last = substr($num, -1);
if (($last > '3') || ((strlen($num) > 1) && (substr($num, -2, 1) == '1'))) {
return 'th';
} else {
return $suffix_arr[$last];
}
}