1   2// 正确地显示复数  3if(!function_exists('_plurals_format'))
  4{
  5/**
  6     * 正确的使用复数    
  7     * @access   public
  8     * @author   zhaoyingnan   2016-02-17 11:53
  9     * @param    string        $sPluralName    非复数形式的名称
 10     * @param    int           $iAmount        数量
 11     * @return   string
 12     * @note    
 13     **/ 14function _plurals_format($sPluralName, $iAmount)
 15    {
 16if(!$sPluralName || !is_numeric($iAmount) || $iAmount  17return '';
 18// 特殊的复数形式 19$arPluralName = array(
 20             'addendum'=>'addenda',
 21             'alga'=>'algae',
 22             'alumna'=>'alumnae',
 23             'alumnus'=>'alumni',
 24             'analysis'=>'analyses',
 25             'antenna'=>'antennas',//antennae 26             'apparatus'=>'apparatuses',
 27             'appendix'=>'appendices',//appendixes 28             'axis'=>'axes',
 29             'bacillus'=>'bacilli',
 30             'bacterium'=>'bacteria',
 31             'basis'=>'bases',
 32             'beau'=>'beaux',
 33             'bison'=>'bison',
 34             'buffalo'=>'buffalos',//buffaloes 35             'bureau'=>'bureaus',
 36             'bus'=>'busses',//buses 37             'cactus'=>'cactuses',//cacti 38             'calf'=>'calves',
 39             'child'=>'children',
 40             'corps'=>'corps',
 41             'corpus'=>'corpora',//corpuses 42             'crisis'=>'crises',
 43             'criterion'=>'criteria',
 44             'curriculum'=>'curricula',
 45             'datum'=>'data',
 46             'deer'=>'deer',
 47             'die'=>'dice',
 48             'dwarf'=>'dwarfs',//dwarves 49             'diagnosis'=>'diagnoses',
 50             'echo'=>'echoes',
 51             'elf'=>'elves',
 52             'ellipsis'=>'ellipses',
 53             'embargo'=>'embargoes',
 54             'emphasis'=>'emphases',
 55             'erratum'=>'errata',
 56             'fireman'=>'firemen',
 57             'fish'=>'fish',//fishes 58             'focus'=>'focuses',
 59             'foot'=>'feet',
 60             'formula'=>'formulas',
 61             'fungus'=>'fungi',//funguses 62             'genus'=>'genera',
 63             'goose'=>'geese',
 64             'half'=>'halves',
 65             'hero'=>'heroes',
 66             'hippopotamus'=>'hippopotami',//hippopotamuses 67             'hoof'=>'hoofs',//hooves 68             'hypothesis'=>'hypotheses',
 69             'index'=>'indices',//indexes 70             'knife'=>'knives',
 71             'leaf'=>'leaves',
 72             'life'=>'lives',
 73             'loaf'=>'loaves',
 74             'louse'=>'lice',
 75             'man'=>'men',
 76             'matrix'=>'matrices',
 77             'means'=>'means',
 78             'medium'=>'media',
 79             'memorandum'=>'memoranda',
 80             'millennium'=>'millenniums',//milennia 81             'moose'=>'moose',
 82             'mosquito'=>'mosquitoes',
 83             'mouse'=>'mice',
 84             'nebula'=>'nebulae',//nebulas 85             'neurosis'=>'neuroses',
 86             'nucleus'=>'nuclei',
 87             'oasis'=>'oases',
 88             'octopus'=>'octopi',//octopuses 89             'ovum'=>'ova',
 90             'ox'=>'oxen',
 91             'paralysis'=>'paralyses',
 92             'parenthesis'=>'parentheses',
 93             'person'=>'people',
 94             'phenomenon'=>'phenomena',
 95             'potato'=>'potatoes',
 96             'radius'=>'radii',//radiuses 97             'scarf'=>'scarfs',//scarves 98             'self'=>'selves',
 99             'series'=>'series',
100             'sheep'=>'sheep',
101             'shelf'=>'shelves',
102             'scissors'=>'scissors',
103             'species'=>'species',
104             'stimulus'=>'stimuli',
105             'stratum'=>'strata',
106             'syllabus'=>'syllabi',//syllabuses107             'symposium'=>'symposia',//symposiums108             'synthesis'=>'syntheses',
109             'synopsis'=>'synopses',
110             'tableau'=>'tableaux',
111             'that'=>'those',
112             'thesis'=>'theses',
113             'thief'=>'thieves',
114             'this'=>'these',
115             'tomato'=>'tomatoes',
116             'tooth'=>'teeth',
117             'torpedo'=>'torpedoes',
118             'vertebra'=>'vertebrae',
119             'veto'=>'vetoes',
120             'vita'=>'vitae',
121             'watch'=>'watches',
122             'wife'=>'wives',
123             'wolf'=>'wolves',
124             'woman'=>'women',
125             'zero'=>'zeros',//zeroes126        );
127128// 如果只有一个129if($iAmount == 1)
130return$sPluralName;
131132// 如果超过一个,并且是特殊的复数形式133if(isset($arPluralName[$sPluralName]))
134return$arPluralName[$sPluralName];
135136// 超过一个,并且是一个标准的复数形式137return$sPluralName.'s';
138    }
139}
140141echo 'Sybil ate three '._plurals_format('biscuit', 3).', one after the other.',PHP_EOL;
142echo 'The two '._plurals_format('woman', 2).' will meet tomorrow in the final.';
登录后复制

以上就介绍了PHP正确的使用复数,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

09-10 10:36