mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
parents-merge 41017 - Added Text::LimitSentences
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@45060 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
528fb572fe
commit
202b7fd9b6
@ -57,6 +57,34 @@ class Text extends DBField {
|
|||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Limit sentences, can be controlled by passing an integer.
|
||||||
|
* @param int $sentCount The amount of sentences you want.
|
||||||
|
*/
|
||||||
|
function LimitSentences($sentCount = 2) {
|
||||||
|
$data = Convert::xml2raw($this->value);
|
||||||
|
$sentences = explode('.', $data);
|
||||||
|
if(count($sentences) == 1) {
|
||||||
|
return $sentences[0] . '.';
|
||||||
|
} elseif(count($sentences) > 1) {
|
||||||
|
if(is_numeric($sentCount) && $sentCount != 0) {
|
||||||
|
if($sentCount == 1) {
|
||||||
|
$output = $sentences[0] . '. ';
|
||||||
|
} else {
|
||||||
|
for($i = 1; $i <= $sentCount-1; $i++) {
|
||||||
|
if($sentences[0]) {
|
||||||
|
$output .= $sentences[0] . '. ';
|
||||||
|
}
|
||||||
|
if($sentences[$i]) {
|
||||||
|
$output .= $sentences[$i] . '. ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caution: Not XML/HTML-safe - does not respect closing tags.
|
* Caution: Not XML/HTML-safe - does not respect closing tags.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user