Last active
August 29, 2015 13:56
-
-
Save dominikwilkowski/8968493 to your computer and use it in GitHub Desktop.
TINY TRUNCATE WORD FUNCTION
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
<?php | |
/*****************************| TRUNCATE WORDS |*****************************/ | |
/** | |
* TINY TRUNCATE WORD FUNCTION | |
* | |
* @param string $t String to be shortened | |
* @param int $count Number of words to output | |
* @param boolen $dots Add dots at the end with string is larger than $count. (optional) [default=true] | |
* | |
* @return string of $count words with added dots | |
*/ | |
function trancateWords($t, $count, $dots = true) { | |
$words = implode(" ", array_slice( explode(" ", $t), 0, $count) ); | |
if( strlen($t) > strlen($words) && $dots ) $words .= '...'; | |
return $words; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment