Well, it's a very locale-specific problem. There's no such function in PHP and I doubt there's such a function in PostgreSQL.
But there's no real need for one:
$number=241;
switch(substr($number,-1))
{ case 1: $number.="st"; break;
case 2: $number.="nd"; break;
case 3: $number.="rd"; break;
default: $number.="th"; break;
}
echo $number;