Created
February 24, 2015 19:20
-
-
Save celsofabri/82bedc172d7b582390b4 to your computer and use it in GitHub Desktop.
Returns hum summary for any rope word / Retorna um resumo de qualquer string por palavra
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
/** | |
* Retorna um resumo de qualquer string por palavra | |
* @param string $string A string que será cortada | |
* @param int $max O número máximo de palavras | |
* @return string A string cortada | |
* By Cezinha <3 | |
*/ | |
function resumo($string, $max, $final = '...') { | |
$string = explode(' ', trim($string)); | |
if (count($string) > $max) { | |
$string = array_slice($string, 0, $max); | |
$string = implode(' ', $string); | |
$string .= $final; | |
} | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment