Last active
December 22, 2015 00:49
-
-
Save gilsonbp/6392364 to your computer and use it in GitHub Desktop.
Helper de resumo limitando a quantidade de palavras.
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
<?php | |
/** | |
* @author Gilson Paulino <gilsonbp@gmail.com> | |
* @version 1.1 | |
*/ | |
class Zend_View_Helper_Resumo extends Zend_View_Helper_Abstract { | |
/** | |
* Reduz um texto com base na quantiade de palavras | |
* @param type $string Texto a ser reduzido | |
* @param type $quant_palavras Quantidade de palavras para o retorno | |
* @return string Retorna o texto reduzido | |
*/ | |
public function resumo($string, $quant_palavras) { | |
$texto = strip_tags($string); | |
$textoA = explode(' ', $texto); | |
if ($quant_palavras < count($textoA)) { | |
$resumo = ''; | |
for ($i = 0; $i < $quant_palavras; $i++) { | |
$resumo = $resumo . " " . $textoA[$i]; | |
} | |
return $resumo . '...'; | |
} else { | |
return $texto; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment