Skip to content

Instantly share code, notes, and snippets.

@ttribeiro
Forked from marcosbrasil/text_cut.php
Created June 22, 2012 14:10
Show Gist options
  • Select an option

  • Save ttribeiro/2972925 to your computer and use it in GitHub Desktop.

Select an option

Save ttribeiro/2972925 to your computer and use it in GitHub Desktop.
FUnção PHP para limitar texto sem cortar palavras
<?php
function limitarTexto($texto, $limite){
$texto = substr($texto, 0, strrpos(substr($texto, 0, $limite), ' ')) . '...';
return $texto;
}
// String a ser limitada
$string = 'Como limitar caracteres sem cortar as palavras com PHP';
// Mostrando a string limitada em 25 caracteres.
print(limitarTexto($string, $limite = 25));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment