Skip to content

Instantly share code, notes, and snippets.

@danilowm
Created March 8, 2012 01:40
Show Gist options
  • Select an option

  • Save danilowm/1997898 to your computer and use it in GitHub Desktop.

Select an option

Save danilowm/1997898 to your computer and use it in GitHub Desktop.
Cortar strings sem cortar palavras
<?php
function truncate($str, $len, $end='') {
return substr($str, 0, strrpos(substr($str, 0, $len), ' ')) . $end;
}
$mensagem = 'Este texto é muito grande e eu quero cortar sem cortar as palavras no meio';
echo truncate($mensagem, 5, '...');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment