/ Published in: PHP
Para não cortar a palavra ao meio.
Its for not to cut a word in the middle.
//Ex:
Então, chapeuzinho vermelho decide tomar no c... (feio, nao?)
Então, chapeuzinho vermelho decide tomar no cantinho...
Its for not to cut a word in the middle.
//Ex:
Então, chapeuzinho vermelho decide tomar no c... (feio, nao?)
Então, chapeuzinho vermelho decide tomar no cantinho...
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
define("TRUNC_BEFORE_LENGHT", 0); define("TRUNC_AFTER_LENGHT", 1); function str_truncate($str, $length, $rep=TRUNC_BEFORE_LENGHT){ //adicionada em 27/06/2006 para corrigir um bug if(strlen($str)<=$length) return $str; if($rep == TRUNC_BEFORE_LENGHT) $oc = strrpos(substr($str,0,$length),' '); if($rep == TRUNC_AFTER_LENGHT) $oc = strpos(substr($str,$length),' ') + $length; return substr($str, 0, $oc); } <? $frase = "Então, chapeuzinho vermelho decide tomar no cantinho bem escondida, uma lata de leite condensado."; print str_truncate($frase, 45, TRUNC_AFTER_LENGHT) . '...'; ?>