Created
March 8, 2012 01:40
-
-
Save danilowm/1997898 to your computer and use it in GitHub Desktop.
Cortar strings sem cortar palavras
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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