- Create a new php file using any IDE of your choice ( Netbeans,Dreamweaver etc)
- Write the following code inside the file.
- Save in htdocs folder under XAMP.
- Run the file by entering “Localhost” in the browser.
function postfix($cdnl
{
$temp = abs($cdnl) % 10;
$ext = ((abs($cdnl) %100 < 21 && abs($cdnl) %100 > 4) ? 'th'
: (($temp< 4) ? ($temp < 3) ? ($temp < 2) ? ($temp < 1)
? 'th' : 'st' : 'nd' : 'rd' :
'th'));
return $cdnl.$ext;
}
Here is the function to do the task. Just copy the function and paste in your project. The name of the function is postfix. As you can see, the function is accepting one parameter which is the number you want to add postfix.
For calling the function,
echo postfix(“200”);
This will print 200th