/ 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...
Expand |
Embed | Plain Text
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."; ?>
You need to login to post a comment.
