Skip to content

Instantly share code, notes, and snippets.

@jplouback
Forked from marcosbrasil/text_cut.php
Created July 4, 2017 19:51
Show Gist options
  • Save jplouback/cd39ca5f8a16cf490067f7d57cd00aa1 to your computer and use it in GitHub Desktop.
Save jplouback/cd39ca5f8a16cf490067f7d57cd00aa1 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