-
-
Save jplouback/cd39ca5f8a16cf490067f7d57cd00aa1 to your computer and use it in GitHub Desktop.
FUnção PHP para limitar texto sem cortar palavras
This file contains 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 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