當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Inflector::inflections方法代碼示例

本文整理匯總了PHP中Inflector::inflections方法的典型用法代碼示例。如果您正苦於以下問題:PHP Inflector::inflections方法的具體用法?PHP Inflector::inflections怎麽用?PHP Inflector::inflections使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Inflector的用法示例。


在下文中一共展示了Inflector::inflections方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: singularize

 function singularize($string)
 {
     $inflections =& Inflector::inflections();
     if (in_array(strtolower($string), $inflections->uncountables)) {
         return $string;
     }
     foreach ($inflections->singulars as $singular) {
         list($rule, $replacement) = $singular;
         # This looks redundant but is needed for PHP4 compatibility
         if (preg_match($rule, $string)) {
             $result = preg_replace($rule, $replacement, $string, 1);
             break;
         }
     }
     if (!isset($result)) {
         $result = $string;
     }
     return $result;
 }
開發者ID:kakra,項目名稱:adodbrecord,代碼行數:19,代碼來源:Inflector.class.php

示例2:

Inflector::inflections(function ($inflect) {
    $inflect->plural('/$/', 's');
    $inflect->plural('/s$/i', 's');
    $inflect->plural('/^(ax|test)is$/i', '\\1es');
    $inflect->plural('/(octop|vir)us$/i', '\\1i');
    $inflect->plural('/(octop|vir)i$/i', '\\1i');
    $inflect->plural('/(alias|status)$/i', '\\1es');
    $inflect->plural('/(bu)s$/i', '\\1ses');
    $inflect->plural('/(buffal|tomat)o$/i', '\\1oes');
    $inflect->plural('/([ti])um$/i', '\\1a');
    $inflect->plural('/([ti])a$/i', '\\1a');
    $inflect->plural('/sis$/i', 'ses');
    $inflect->plural('/(?:([^f])fe|([lr])f)$/i', '\\1\\2ves');
    $inflect->plural('/(hive)$/i', '\\1s');
    $inflect->plural('/([^aeiouy]|qu)y$/i', '\\1ies');
    $inflect->plural('/(x|ch|ss|sh)$/i', '\\1es');
    $inflect->plural('/(matr|vert|ind)(?:ix|ex)$/i', '\\1ices');
    $inflect->plural('/^(m|l)ouse$/i', '\\1ice');
    $inflect->plural('/^(m|l)ice$/i', '\\1ice');
    $inflect->plural('/^(ox)$/i', '\\1en');
    $inflect->plural('/^(oxen)$/i', '\\1');
    $inflect->plural('/(quiz)$/i', '\\1zes');
    $inflect->singular('/s$/i', '');
    $inflect->singular('/(ss)$/i', '\\1');
    $inflect->singular('/(n)ews$/i', '\\1ews');
    $inflect->singular('/([ti])a$/i', '\\1um');
    $inflect->singular('/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i', '\\1\\2sis');
    $inflect->singular('/(^analy)(sis|ses)$/i', '\\1sis');
    $inflect->singular('/([^f])ves$/i', '\\1fe');
    $inflect->singular('/(hive)s$/i', '\\1');
    $inflect->singular('/(tive)s$/i', '\\1');
    $inflect->singular('/([lr])ves$/i', '\\1f');
    $inflect->singular('/([^aeiouy]|qu)ies$/i', '\\1y');
    $inflect->singular('/(s)eries$/i', '\\1eries');
    $inflect->singular('/(m)ovies$/i', '\\1ovie');
    $inflect->singular('/(x|ch|ss|sh)es$/i', '\\1');
    $inflect->singular('/^(m|l)ice$/i', '\\1ouse');
    $inflect->singular('/(bus)(es)?$/i', '\\1');
    $inflect->singular('/(o)es$/i', '\\1');
    $inflect->singular('/(shoe)s$/i', '\\1');
    $inflect->singular('/(cris|test)(is|es)$/i', '\\1is');
    $inflect->singular('/^(a)x[ie]s$/i', '\\1xis');
    $inflect->singular('/(octop|vir)(us|i)$/i', '\\1us');
    $inflect->singular('/(alias|status)(es)?$/i', '\\1');
    $inflect->singular('/^(ox)en/i', '\\1');
    $inflect->singular('/(vert|ind)ices$/i', '\\1ex');
    $inflect->singular('/(matr)ices$/i', '\\1ix');
    $inflect->singular('/(quiz)zes$/i', '\\1');
    $inflect->singular('/(database)s$/i', '\\1');
    $inflect->irregular('person', 'people');
    $inflect->irregular('man', 'men');
    $inflect->irregular('child', 'children');
    $inflect->irregular('sex', 'sexes');
    $inflect->irregular('move', 'moves');
    $inflect->irregular('cow', 'kine');
    $inflect->irregular('zombie', 'zombies');
    $inflect->uncountable('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans', 'police');
});
開發者ID:koenpunt,項目名稱:php-inflector,代碼行數:58,代碼來源:Inflections.php


注:本文中的Inflector::inflections方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。