Creates an exceprt of a string
It removes all html tags first and then uses str::short
static public excerpt ( string $string, integer $chars = 140, boolean $removehtml = true, string $rep = '…' ) : string | ||
$string | string | The string to be shortened |
$chars | integer | The final number of characters the string should have |
$removehtml | boolean | True: remove the HTML tags from the string first |
$rep | string | The element, which should be added if the string is too long. Ellipsis is the default. |
return | string | The shortened string |
function excerpt($text, $length = 140, $markdown = true) { return str::excerpt(kirbytext::init($text, $markdown), $length); }
function excerpt($text, $length = 140) { return str::excerpt(kirbytext($text), $length); }
/** * Creates an excerpt without html and kirbytext * * @param mixed $text Variable object or string * @param int $length The number of characters which should be included in the excerpt * @param array $params an array of options for kirbytext: array('markdown' => true, 'smartypants' => true) * @return string The shortened text */ function excerpt($text, $length = 140, $mode = 'chars') { if (strtolower($mode) == 'words') { $text = str::excerpt(kirbytext($text), 0); if (str_word_count($text, 0) > $length) { $words = str_word_count($text, 2); $pos = array_keys($words); $text = str::substr($text, 0, $pos[$length]) . '...'; } return $text; } else { return str::excerpt(kirbytext($text), $length); } }