当前位置: 首页>>代码示例>>PHP>>正文


PHP plural函数代码示例

本文整理汇总了PHP中plural函数的典型用法代码示例。如果您正苦于以下问题:PHP plural函数的具体用法?PHP plural怎么用?PHP plural使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了plural函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: singular_plural

 function singular_plural($int = 0, $text = NULL)
 {
     if ((int) $int > 1) {
         return (int) $int . nbs() . plural($text);
     }
     return (int) $int . nbs() . $text;
 }
开发者ID:soniibrol,项目名称:package,代码行数:7,代码来源:extension_helper.php

示例2: getTableName

 /**
  * Gets the specified table name of the model.
  *
  * @return string
  */
 public function getTableName()
 {
     if (!$this->table) {
         return plural(strtolower(get_class($this)));
     }
     return $this->table;
 }
开发者ID:rougin,项目名称:wildfire,代码行数:12,代码来源:ModelTrait.php

示例3: pleac_Printing_Correct_Plurals

function pleac_Printing_Correct_Plurals()
{
    function pluralise($value, $root, $singular = '', $plural = 's')
    {
        return $root . ($value > 1 ? $plural : $singular);
    }
    // ------------
    $duration = 1;
    printf("It took %d %s\n", $duration, pluralise($duration, 'hour'));
    printf("%d %s %s enough.\n", $duration, pluralise($duration, 'hour'), pluralise($duration, '', 'is', 'are'));
    $duration = 5;
    printf("It took %d %s\n", $duration, pluralise($duration, 'hour'));
    printf("%d %s %s enough.\n", $duration, pluralise($duration, 'hour'), pluralise($duration, '', 'is', 'are'));
    // ----------------------------
    function plural($singular)
    {
        $s2p = array('/ss$/' => 'sses', '/([psc]h)$/' => '${1}es', '/z$/' => 'zes', '/ff$/' => 'ffs', '/f$/' => 'ves', '/ey$/' => 'eys', '/y$/' => 'ies', '/ix$/' => 'ices', '/([sx])$/' => '$1es', '$' => 's');
        foreach ($s2p as $s => $p) {
            if (preg_match($s, $singular)) {
                return preg_replace($s, $p, $singular);
            }
        }
    }
    // ------------
    foreach (array('mess', 'index', 'leaf', 'puppy') as $word) {
        printf("%6s -> %s\n", $word, plural($word));
    }
}
开发者ID:Halfnhav4,项目名称:pfff,代码行数:28,代码来源:Printing_Correct_Plurals.php

示例4: generate

 /**
  * Generates set of code based on data.
  *
  * @return array
  */
 public function generate()
 {
     $this->prepareData($this->data);
     $columnFields = ['name', 'description', 'label'];
     $table = $this->describe->getTable($this->data['name']);
     foreach ($table as $column) {
         if ($column->isAutoIncrement()) {
             continue;
         }
         $field = strtolower($column->getField());
         $method = 'set_' . $field;
         $this->data['camel'][$field] = lcfirst(camelize($method));
         $this->data['underscore'][$field] = underscore($method);
         array_push($this->data['columns'], $field);
         if ($column->isForeignKey()) {
             $referencedTable = Tools::stripTableSchema($column->getReferencedTable());
             $this->data['foreignKeys'][$field] = $referencedTable;
             array_push($this->data['models'], $referencedTable);
             $dropdown = ['list' => plural($referencedTable), 'table' => $referencedTable, 'field' => $field];
             if (!in_array($field, $columnFields)) {
                 $field = $this->describe->getPrimaryKey($referencedTable);
                 $dropdown['field'] = $field;
             }
             array_push($this->data['dropdowns'], $dropdown);
         }
     }
     return $this->data;
 }
开发者ID:rougin,项目名称:combustor,代码行数:33,代码来源:ControllerGenerator.php

示例5: fechaTextual

 /**
  * Calcula la diferencia entre dos timestamps y retorna un array con las
  * unidades temporales más altas, en orden descendente (año, mes, semana, dia. etc).
  * Sirve para calcular las fechas de "hace x minutos" o "en x semanas".
  * Maneja automáticamente los singulares y plurales.
  * 
  * @param  integer $timestamp Tiempo a comparar, en el pasado o futuro
  * @param  integer $unidades  Unidades temporales a mostrar. 
  *                            Ej: 1 puede devolver "hora", 2 puede devolver
  *                            "semanas" y "dias".
  * @param  integer $comparar  Fecha a comparar. Por defecto, time().
  * @return array              Array de 2 o más valores.
  *                            El primero es un booleano que indica si el tiempo está
  *                            en el futuro. El resto son las unidades temporales.
  */
 function fechaTextual($timestamp = 0, $unidades = 2, $comparar = 0)
 {
     if (!is_numeric($timestamp)) {
         return array();
     }
     if (!$comparar) {
         $comparar = time();
     }
     $diferencia = $comparar - $timestamp;
     $fechaEsFutura = $diferencia < 0 ? true : false;
     $valores = array('año' => 0, 'mes' => 0, 'semana' => 0, 'dia' => 0, 'hora' => 0, 'minuto' => 0, 'segundo' => 0);
     $constantes = array('año' => YEAR_IN_SECONDS, 'mes' => MONTH_IN_SECONDS, 'semana' => WEEK_IN_SECONDS, 'dia' => DAY_IN_SECONDS, 'hora' => HOUR_IN_SECONDS, 'minuto' => MINUTE_IN_SECONDS, 'segundo' => 1);
     foreach ($constantes as $k => $constante) {
         if ($diferencia > $constante) {
             $valores[$k] = floor($diferencia / $constante);
             $diferencia = $diferencia % $constante;
         }
     }
     $retorno = array($fechaEsFutura);
     $plural = array('año' => 'años', 'mes' => 'meses', 'semana' => 'semanas', 'dia' => 'dias', 'hora' => 'horas', 'minuto' => 'minutos', 'segundo' => 'segundos');
     while ($unidades > 0) {
         foreach ($valores as $k => $v) {
             if ($v != 0) {
                 $retorno[] = $v . ' ' . plural($v, $k, $plural[$k]);
                 unset($valores[$k]);
                 break;
             }
             unset($valores[$k]);
         }
         $unidades--;
     }
     return $retorno;
 }
开发者ID:eliasdorigoni,项目名称:WPBase,代码行数:48,代码来源:utilidades.php

示例6: execute

 /**
  * Executes the command.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return object|\Symfony\Component\Console\Output\OutputInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = Tools::stripTableSchema(plural($input->getArgument('name')));
     if ($input->getOption('keep')) {
         $name = Tools::stripTableSchema($input->getArgument('name'));
     }
     $validator = new ViewValidator($name);
     if ($validator->fails()) {
         $message = $validator->getMessage();
         return $output->writeln('<error>' . $message . '</error>');
     }
     $data = ['isBootstrap' => $input->getOption('bootstrap'), 'isCamel' => $input->getOption('camel'), 'name' => $input->getArgument('name')];
     $generator = new ViewGenerator($this->describe, $data);
     $result = $generator->generate();
     $results = ['create' => $this->renderer->render('Views/create.tpl', $result), 'edit' => $this->renderer->render('Views/edit.tpl', $result), 'index' => $this->renderer->render('Views/index.tpl', $result), 'show' => $this->renderer->render('Views/show.tpl', $result)];
     $filePath = APPPATH . 'views/' . $name;
     $create = new File($filePath . '/create.php');
     $edit = new File($filePath . '/edit.php');
     $index = new File($filePath . '/index.php');
     $show = new File($filePath . '/show.php');
     $create->putContents($results['create']);
     $edit->putContents($results['edit']);
     $index->putContents($results['index']);
     $show->putContents($results['show']);
     $create->close();
     $edit->close();
     $index->close();
     $show->close();
     $message = 'The views folder "' . $name . '" has been created successfully!';
     return $output->writeln('<info>' . $message . '</info>');
 }
开发者ID:rougin,项目名称:combustor,代码行数:38,代码来源:CreateViewCommand.php

示例7: getRelativeTime

function getRelativeTime($date)
{
    $time = @strtotime($date);
    $diff = time() - $time;
    if ($diff < 60) {
        return $diff . " second" . plural($diff) . " ago";
    }
    $diff = round($diff / 60);
    if ($diff < 60) {
        return $diff . " minute" . plural($diff) . " ago";
    }
    $diff = round($diff / 60);
    if ($diff < 24) {
        return $diff . " hour" . plural($diff) . " ago";
    }
    $diff = round($diff / 24);
    if ($diff < 7) {
        return $diff . " day" . plural($diff) . " ago";
    }
    $diff = round($diff / 7);
    if ($diff < 4) {
        return $diff . " week" . plural($diff) . " ago";
    }
    if (date('Y', $time) != date('Y', time())) {
        return date("j-M Y", $time);
    }
    return date("j-M", $time);
}
开发者ID:pkdevbox,项目名称:jsbin,代码行数:28,代码来源:list-home-code.php

示例8: edit

 public function edit()
 {
     $sModel = $this->uri->segment(4);
     if (class_exists($sModel)) {
         $oModel = new $sModel();
         $oResult = $oModel->load()->where('id', $this->uri->segment(5))->get();
         //** Build array to populate form
         foreach ($oModel->fieldNames as $sValue) {
             $aOut[$sModel][$sValue] = $oResult->{$sValue};
         }
         //** Any __includes ?
         foreach ($oModel->form as $k => $aValue) {
             if ($k == '__include') {
                 foreach ($aValue['model'] as $k2 => $v2) {
                     //** Add these models to the aFormData array
                     $oObj = new $v2();
                     $oResult = $oObj->load()->where(strtolower($sModel) . '_id', $this->uri->segment(5))->get();
                     foreach ($oObj->fieldNames as $sValue) {
                         $aOut[ucfirst($v2)][$sValue] = $oResult->{$sValue};
                     }
                 }
             }
         }
         $this->aData['aFormData'] = $aOut;
         $this->aData['iEditId'] = $this->uri->segment(5);
         //** each form needs these
         $this->aData['sView'] = 'includes/forms/' . ucfirst(plural($oModel)) . '_form';
         $this->aData['sTarget'] = '/admin/master/listall/' . $sModel;
         $this->load->view('form', $this->aData);
     }
 }
开发者ID:nhc,项目名称:agency-cms,代码行数:31,代码来源:master.php

示例9: relative_time

function relative_time($date)
{
    $diff = time() - $date;
    $poststr = $diff > 0 ? " ago" : "";
    $adiff = abs($diff);
    if ($adiff < 60) {
        return $adiff . " second" . plural($adiff) . $poststr;
    }
    if ($adiff < 3600) {
        // 60*60
        return round($adiff / 60) . " minute" . plural($adiff) . $poststr;
    }
    if ($adiff < 86400) {
        // 24*60*60
        return round($adiff / 3600) . " hour" . plural($adiff) . $poststr;
    }
    if ($adiff < 604800) {
        // 7*24*60*60
        return round($adiff / 86400) . " day" . plural($adiff) . $poststr;
    }
    if ($adiff < 2419200) {
        // 4*7*24*60*60
        return $adiff . " week" . plural($adiff) . $poststr;
    }
    return "on " . date("F j, Y", strtotime($date));
}
开发者ID:bitoncoin,项目名称:faucet-1,代码行数:26,代码来源:core.php

示例10: Orm

 function Orm($name = null, $table = null, $primaryKey = null)
 {
     $this->_assignLibraries();
     $this->_loadHelpers();
     if ($name == null) {
         if ($this->name == null) {
             $this->name = ucfirst(singular(get_class($this)));
         }
     } else {
         $this->name = $name;
     }
     if ($this->alias === null) {
         $this->alias = $this->name;
     }
     if ($table == null) {
         if ($this->table == null) {
             $this->table = plural($this->name);
         }
     } else {
         $this->table = $table;
     }
     $this->table = $this->prefix . $this->table;
     if ($primaryKey == null) {
         if ($this->primaryKey == null) {
             $this->primaryKey = 'id';
         }
     } else {
         $this->primaryKey = $primaryKey;
     }
     Registry::addObject($this->alias, $this);
     $this->createLinks();
 }
开发者ID:vcrack,项目名称:ciorta,代码行数:32,代码来源:Orm.php

示例11: index

 public function index()
 {
     $this->document->setTitle(tt('BitsyBay - Sell and Buy Digital Content with BitCoin'), false);
     if (isset($this->request->get['route'])) {
         $this->document->addLink(HTTP_SERVER, 'canonical');
     }
     if ($this->auth->isLogged()) {
         $data['title'] = sprintf(tt('Welcome, %s!'), $this->auth->getUsername());
         $data['user_is_logged'] = true;
     } else {
         $data['title'] = tt('Welcome to the BitsyBay store!');
         $data['user_is_logged'] = false;
     }
     $total_products = $this->model_catalog_product->getTotalProducts(array());
     $data['total_products'] = sprintf(tt('%s %s'), $total_products, plural($total_products, array(tt('offer'), tt('offers'), tt('offers'))));
     $total_categories = $this->model_catalog_category->getTotalCategories();
     $data['total_categories'] = sprintf(tt('%s %s'), $total_categories, plural($total_categories, array(tt('category'), tt('categories'), tt('categories'))));
     $total_sellers = $this->model_account_user->getTotalSellers();
     $data['total_sellers'] = sprintf(tt('%s %s'), $total_sellers, plural($total_sellers, array(tt('seller'), tt('sellers'), tt('sellers'))));
     $total_buyers = $this->model_account_user->getTotalUsers();
     $data['total_buyers'] = sprintf(tt('%s %s'), $total_buyers, plural($total_buyers, array(tt('buyer'), tt('buyers'), tt('buyers'))));
     $redirect = base64_encode($this->url->getCurrentLink($this->request->getHttps()));
     $data['login_action'] = $this->url->link('account/account/login', 'redirect=' . $redirect, 'SSL');
     $data['href_account_create'] = $this->url->link('account/account/create', 'redirect=' . $redirect, 'SSL');
     $data['module_search'] = $this->load->controller('module/search', array('class' => 'col-lg-8 col-lg-offset-2'));
     $data['module_latest'] = $this->load->controller('module/latest', array('limit' => 8));
     $data['footer'] = $this->load->controller('common/footer');
     $data['header'] = $this->load->controller('common/header');
     $this->response->setOutput($this->load->view('common/home.tpl', $data));
 }
开发者ID:RustyNomad,项目名称:bitsybay,代码行数:30,代码来源:home.php

示例12: index

 public function index()
 {
     $this->document->setTitle(tt('BitsyBay - Sell and Buy Digital Creative with BitCoin'), false);
     $this->document->setDescription(tt('BTC Marketplace for royalty-free photos, arts, templates, codes, books and other digital creative with BitCoin. Only quality and legal content from them authors. Free seller fee up to 2016!'));
     $this->document->setKeywords(tt('bitsybay, bitcoin, btc, indie, marketplace, store, buy, sell, royalty-free, photos, arts, illustrations, 3d, templates, codes, extensions, books, content, digital, creative, quality, legal'));
     if (isset($this->request->get['route'])) {
         $this->document->addLink(URL_BASE, 'canonical');
     }
     if ($this->auth->isLogged()) {
         $data['title'] = sprintf(tt('Welcome, %s!'), $this->auth->getUsername());
         $data['user_is_logged'] = true;
     } else {
         $data['title'] = tt('Welcome to the BitsyBay store!');
         $data['user_is_logged'] = false;
     }
     $total_products = $this->model_catalog_product->getTotalProducts(array());
     $data['total_products'] = sprintf(tt('%s %s'), $total_products, plural($total_products, array(tt('offer'), tt('offers'), tt('offers'))));
     $total_categories = $this->model_catalog_category->getTotalCategories();
     $data['total_categories'] = sprintf(tt('%s %s'), $total_categories, plural($total_categories, array(tt('category'), tt('categories'), tt('categories'))));
     $total_sellers = $this->model_account_user->getTotalSellers();
     $data['total_sellers'] = sprintf(tt('%s %s'), $total_sellers, plural($total_sellers, array(tt('sellers'), tt('sellers'), tt('sellers'))));
     $total_buyers = $this->model_account_user->getTotalUsers();
     $data['total_buyers'] = sprintf(tt('%s %s'), $total_buyers, plural($total_buyers, array(tt('buyers'), tt('buyers'), tt('buyers'))));
     $redirect = base64_encode($this->url->getCurrentLink());
     $data['login_action'] = $this->url->link('account/account/login', 'redirect=' . $redirect);
     $data['href_account_create'] = $this->url->link('account/account/create', 'redirect=' . $redirect);
     $data['module_search'] = $this->load->controller('module/search', array('class' => 'col-lg-8 col-lg-offset-2'));
     $data['module_latest'] = $this->load->controller('module/latest', array('limit' => 4));
     $data['footer'] = $this->load->controller('common/footer');
     $data['header'] = $this->load->controller('common/header');
     $this->response->setOutput($this->load->view('common/home.tpl', $data));
 }
开发者ID:babilavena,项目名称:bitsybay,代码行数:32,代码来源:home.php

示例13: table_torch_nav

function table_torch_nav()
{
    $CI =& get_instance();
    $tables = $CI->config->item('torch_tables');
    $prefs = $tables[TORCH_TABLE];
    $extra_links = $CI->config->item('table_extra_nav_links');
    if (isset($_SERVER['HTTP_REFERER'])) {
        $refer = $_SERVER['HTTP_REFERER'];
    } else {
        $refer = CUR_CONTROLLER;
    }
    $str = "<ul id=\"navHeader\">\n";
    if (TORCH_METHOD == 'edit' or TORCH_METHOD == 'add') {
        $str .= "<li class=\"backLink\"><a href=\"{$refer}\">" . $CI->lang->line('table_torch_back_to_listing') . "</a></li>\n";
    } else {
        if (TORCH_METHOD == 'listing' and $prefs['add'] == TRUE) {
            $str .= "<li class=\"backLink\">\n" . anchor(CUR_CONTROLLER . '/' . CUR_METHOD . "/add/" . TORCH_TABLE, $CI->lang->line('table_torch_add_new_link')) . "</li>\n";
        }
    }
    foreach ($tables as $key => $table) {
        if ($key == TORCH_TABLE) {
            $class = 'active';
        } else {
            $class = '';
        }
        $label = ucwords(plural(table_torch_title($key)));
        $url = site_url(CUR_CONTROLLER . '/' . CUR_METHOD . '/listing/' . $key);
        $str .= "<li><a href=\"{$url}\" class=\"{$class}\">{$label}</a></li>\n";
    }
    foreach ($extra_links as $url => $label) {
        $str .= "<li>" . anchor($url, $label) . "</li>\n";
    }
    return $str . "\n</ul>\n";
}
开发者ID:souparno,项目名称:getsparks.org,代码行数:34,代码来源:table_torch_helper.php

示例14: test_plural

 public function test_plural()
 {
     $strs = array('telly' => 'tellies', 'smelly' => 'smellies', 'abjectness' => 'abjectnesses', 'smell' => 'smells', 'witch' => 'witches', 'equipment' => 'equipment');
     foreach ($strs as $str => $expect) {
         $this->assertEquals($expect, plural($str));
     }
 }
开发者ID:saiful1105020,项目名称:Under-Construction-Bracathon-Project-,代码行数:7,代码来源:inflector_helper_test.php

示例15: get_relative_date

function get_relative_date($date)
{
    /*
    Returns relative(more human) date string.
    Uses: `plural`.
    
    Usage:
    `get_relative_date(get_the_date())`
    */
    $diff = time() - strtotime($date);
    if ($diff < 60) {
        return $diff . " second" . plural($diff) . " ago";
    }
    $diff = round($diff / 60);
    if ($diff < 60) {
        return $diff . " minute" . plural($diff) . " ago";
    }
    $diff = round($diff / 60);
    if ($diff < 24) {
        return $diff . " hour" . plural($diff) . " ago";
    }
    $diff = round($diff / 24);
    if ($diff < 7) {
        return $diff . " day" . plural($diff) . " ago";
    }
    $diff = round($diff / 7);
    if ($diff < 4) {
        return $diff . " week" . plural($diff) . " ago";
    }
    return date("F j, Y", strtotime($date));
}
开发者ID:staydecent,项目名称:wp-sourdough,代码行数:31,代码来源:utilities.php


注:本文中的plural函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。