Last active
August 29, 2015 14:18
-
-
Save dellow/5aca0ce47b0dc3838453 to your computer and use it in GitHub Desktop.
Cuts a string by word count.
This file contains 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
/** | |
* word_limit | |
* Cuts a string by word count. | |
* | |
* @since 1.0.0 | |
* @version 1.0.0 | |
**/ | |
function word_limit($string, $limit, $end = '…'){ | |
$words = explode(" ", $string); | |
return (count($words) > $limit) ? implode(" ", array_splice($words, 0, $limit)) . $end : null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment