Created
October 7, 2019 08:52
-
-
Save garyconstable/c66cd2850c751d89c06900a84d90fe00 to your computer and use it in GitHub Desktop.
Revisions
-
garyconstable revised this gist
Oct 7, 2019 . 1 changed file with 33 additions and 29 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,38 +1,42 @@ <?php /** * Take the landing page content, strip the tags and return an shortened versions. * * @param $text * @param bool $strip_tags * @param int $max_length * @param string $cut_off * @param bool $keep_word * @return bool|string */ function getExcerpt($text, $strip_tags = true, $max_length = 140, $cut_off = '...', $keep_word = true) { if ($strip_tags) { $text = strip_tags($text); } if (strlen($text) <= $max_length) { return $text; } if (strlen($text) > $max_length) { if ($keep_word) { $text = substr($text, 0, $max_length + 1); if ($last_space = strrpos($text, ' ')) { $text = substr($text, 0, $last_space); $text = rtrim($text); $text .= $cut_off; } } else { $text = substr($text, 0, $max_length); $text = rtrim($text); $text .= $cut_off; } } return $text; } ?> -
garyconstable created this gist
Oct 7, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ /** * Take the landing page content, strip the tags and return an shortened versions. * * @param $text * @param bool $strip_tags * @param int $max_length * @param string $cut_off * @param bool $keep_word * @return bool|string */ protected function getExcerpt($text, $strip_tags = true, $max_length = 140, $cut_off = '...', $keep_word = true) { if ($strip_tags) { $text = strip_tags($text); } if (strlen($text) <= $max_length) { return $text; } if (strlen($text) > $max_length) { if ($keep_word) { $text = substr($text, 0, $max_length + 1); if ($last_space = strrpos($text, ' ')) { $text = substr($text, 0, $last_space); $text = rtrim($text); $text .= $cut_off; } } else { $text = substr($text, 0, $max_length); $text = rtrim($text); $text .= $cut_off; } } return $text; }