Forcing a break on big words / multiple characters

Visiting Digg today I notice this:
big words - digg example

This is really common problem on user generated sites. HTML does not force a break when the word or multiple characters are longer then the provided space.

I normally solve this in PHP with something like this:

function mywrap($string, $max_length)
{
$separate_words = explode(" ", $string);
for($i = 0; $i < count($separate_words); $i++)
{
if( strlen($separate_words[$i]) > $max_length )
{
$separate_words[$i] = wordwrap($separate_words[$i], $max_length,"<br />", true);
}
}
$string = implode(" ", $separate_words);
return $string;
}

Where $string is the text to verify and $max_length is the max number of characters in the space provided.

Hope it helps someone

Deixar uma resposta

O seu endereço de email não será publicado. Campos obrigatórios marcados com *

*

Pode usar estas etiquetas HTML e atributos: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>