Advertisement
mendigo

QuebraLinha

Aug 16th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. // FUNCAO QUE QUEBRA LINHAS
  2. // ENTRADA          -> $string  : frase de entrada a ser quebrada ( STRING ).
  3. // ENTRADA          -> $max     : Qual caracter que deve ser quebrado ( INT ).
  4. // ENTRADA          -> $quebra  : Oque vai quebra a linha pode ser em branco padrao ( <br> ).
  5. // SAIDA            -> restona a frase quebrada
  6. function QuebraDeLinha($string, $max = 50, $quebra = "\n"){
  7.     if( strlen($string) > $max ){
  8.        $strings = explode(' ',$string);
  9.        foreach($strings as $a => $b ){
  10.             if( strlen( $tmp.' '.$b ) > $max ){
  11.                 $str_tmp .= $tmp.$quebra;
  12.                 $tmp = '';
  13.             }else{
  14.             $tmp .= ' '.$b;
  15.             }
  16.        }
  17.        $str_tmp .= $tmp;
  18.     }else{
  19.         $str_tmp = $string;
  20.     }
  21.     return $str_tmp;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement