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


PHP str::plural方法代码示例

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


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

示例1: unix2exactrelative

 public static function unix2exactrelative($date, $show_weeks = TRUE, $format = "\\o\n F j, Y")
 {
     $diff = time() - $date;
     if ($diff < 60) {
         return $diff . " " . str::plural('second', $diff) . " ago";
     }
     $diff = round($diff / 60);
     if ($diff < 60) {
         return $diff . " " . str::plural('minute', $diff) . " ago";
     }
     $diff = round($diff / 60);
     if ($diff < 24) {
         return $diff . " " . str::plural('hour', $diff) . " ago";
     }
     $diff = round($diff / 24);
     if ($diff < 7) {
         return $diff . " " . str::plural('day', $diff) . " ago";
     }
     $diff = round($diff / 7);
     if ($diff < 4 && $show_weeks) {
         return $diff . " " . str::plural('week', $diff) . " ago";
     }
     return date($format, $date);
 }
开发者ID:shnhrrsn-abandoned,项目名称:EightPHP,代码行数:24,代码来源:date.php

示例2: seconds

 /**
  * Formats a second into years, months, days, hours, minutes, seconds.
  * 
  * Example:
  * format::seconds(65) returns "1 minute, 5 seconds"
  * 
  * @param	int		number of seconds
  * @return	string	formatted seconds
  */
 public static function seconds($seconds)
 {
     list($years, $months, $days, $hours, $minutes, $seconds) = explode(":", gmdate("Y:n:j:G:i:s", $seconds));
     $years -= 1970;
     $months--;
     $days--;
     $parts = array();
     if ($years > 0) {
         $parts[] = $years . " " . str::plural("year", $years);
     }
     if ($months > 0) {
         $parts[] = $months . " " . str::plural("month", $months);
     }
     if ($days > 0) {
         $parts[] = $days . " " . str::plural("day", $days);
     }
     if ($hours > 0) {
         $parts[] = $hours . " " . str::plural("hour", $hours);
     }
     if ($minutes > 0) {
         $parts[] = sprintf("%d", $minutes) . " " . str::plural("minute", $minutes);
     }
     if ($seconds > 0) {
         $parts[] = sprintf("%d", $seconds) . " " . str::plural("second", $seconds);
     }
     return implode(", ", $parts);
 }
开发者ID:enormego,项目名称:EightPHP,代码行数:36,代码来源:format.php

示例3: test_plural

 public function test_plural()
 {
     // 0
     $this->assertEquals('zero', str::plural(0, 'many', 'one', 'zero'));
     // 1
     $this->assertEquals('one', str::plural(1, 'many', 'one', 'zero'));
     // 2
     $this->assertEquals('many', str::plural(2, 'many', 'one', 'zero'));
     // 0 without zero
     $this->assertEquals('many', str::plural(0, 'many', 'one'));
 }
开发者ID:bastianallgeier,项目名称:kirby,代码行数:11,代码来源:str.tests.php


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