Skip to content

Instantly share code, notes, and snippets.

@gilsonbp
Last active December 22, 2015 00:49
Show Gist options
  • Save gilsonbp/6392364 to your computer and use it in GitHub Desktop.
Save gilsonbp/6392364 to your computer and use it in GitHub Desktop.
Helper de resumo limitando a quantidade de palavras.
<?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