Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. public function abreviaString($texto, $limite, $tres_p = '...')
  2. {
  3. $totalCaracteres = 0;
  4. $vetorPalavras = explode(" ",$texto);
  5. if(strlen($texto) <= $limite):
  6. $tres_p = "";
  7. $novoTexto = $texto;
  8. else:
  9. $novoTexto = "";
  10. for($i = 0; $i <count($vetorPalavras); $i++):
  11. $totalCaracteres += strlen(" ".$vetorPalavras[$i]);
  12. if($totalCaracteres <= $limite)
  13. $novoTexto .= ' ' . $vetorPalavras[$i];
  14. else break;
  15. endfor;
  16. endif;
  17. return $novoTexto . $tres_p;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement