mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Adding TextHelper::toList(), to create natural-language lists from arrays
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3304 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
c50275de24
commit
1dc6c1128b
1 changed files with 20 additions and 1 deletions
|
@ -189,7 +189,7 @@ class TextHelper extends Helper {
|
|||
return $this->truncate($text, $radius * 2, $ending);
|
||||
}
|
||||
|
||||
if ($radius < strlen($phrase))
|
||||
if ($radius < strlen($phrase)) {
|
||||
$radius = strlen($phrase);
|
||||
}
|
||||
|
||||
|
@ -208,6 +208,25 @@ class TextHelper extends Helper {
|
|||
|
||||
return $excerpt;
|
||||
}
|
||||
/**
|
||||
* Creates a comma separated list where the last two items are joined with 'and', forming natural English
|
||||
*
|
||||
* @param array $list The list to be joined
|
||||
* @return string
|
||||
*/
|
||||
function toList($list) {
|
||||
$r = '';
|
||||
$c = count($list) - 1;
|
||||
|
||||
foreach ($list as $i => $item) {
|
||||
$r .= $item;
|
||||
if ($c > 0 && $i < $c)
|
||||
{
|
||||
$r .= ($i < $c - 1 ? ', ' : ' and ');
|
||||
}
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
/**
|
||||
* Text-to-html parser, similar to Textile or RedCloth, only with a little different syntax.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue