php 为数字增加 st\nd\rd 等
为数字增加 st\nd\rd 等 [代码片段(16行)]
function make_ranked($rank) {
$last = substr( $rank, -1 );
$seclast = substr( $rank, -2, -1 );
if( $last > 3 || $last == 0 ) $ext = 'th';
else if( $last == 3 ) $ext = 'rd';
else if( $last == 2 ) $ext = 'nd';
else $ext = 'st';
if( $last == 1 && $seclast == 1) $ext = 'th';
if( $last == 2 && $seclast == 1) $ext = 'th';
if( $last == 3 && $seclast == 1) $ext = 'th';
return $rank.$ext;
}
- 上一篇:PHP将网址字符串转换成超级链接
- 下一篇:php关联数组快速排序
精彩图集
精彩文章






