本文整理汇总了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);
}
示例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);
}
示例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'));
}