Created
September 17, 2017 17:51
-
-
Save celticwebdesign/2190d53575c6d2c2bf0213e239df6a53 to your computer and use it in GitHub Desktop.
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 characters
// https://stackoverflow.com/questions/965235/how-can-i-truncate-a-string-to-the-first-20-words-in-php | |
function limit_text($text, $limit) { | |
if (str_word_count($text, 0) > $limit) { | |
$words = str_word_count($text, 2); | |
$pos = array_keys($words); | |
$text = substr($text, 0, $pos[$limit]) . '...'; | |
} | |
return $text; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment