Skip to content

Instantly share code, notes, and snippets.

@1-800-jono
Created June 12, 2018 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1-800-jono/5e5598fd4c233a46ba32e14d911b7519 to your computer and use it in GitHub Desktop.
Save 1-800-jono/5e5598fd4c233a46ba32e14d911b7519 to your computer and use it in GitHub Desktop.
PHP - Limit words function.
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