Break long words ...

A

Anonymous

Guest
Hiya

how can I break a word in some other parts ?
I have a fix-width table which has to show some sentensed in it
user will enter some details to show in that table
if he enters like :

Hello , My name is BlaBla ...

I can use word wrap to show details in that table ,
but since user enters something like this :

Hellooooooooooooooooooooooooooooooooooooooo

Then table will stretch !!!
how can I break this word to a fix size ?

Its not all about one word , user input could be something like this :

Helloooooooooooooooooooo my name issssssssssssssssssssss BlaBla

as you can see , the word (HELLO) should break as well as the word (Is)
not rest of the sentence ... so How can I make a function to break
the neccesary words ?
 
Do you mean using this code? :

Code:
body{overflow:hidden;}

but it just hide horizontal scroll bar in the page !
I like to show all the text but like to break them
actually Ive found something :


Code:
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "<br>", 1);

it works good , but it will break all the words ! I just like to
break the long words !

how can I do this ?
 
I have found it :p

here is the code for people who want to use the same function :

Code:
function word_wrap($texte,$lng_max) {
   // Script
   $esp=explode(" ",$texte);
   $i=0;
   $carac_dep=0;
   $tmp_txt="";
   // sur tout la longeur du texte
   while ($i<=count($esp)) {
       $lng_mot=strlen($esp[$i]);
       // si  le mot est trop gd
       if ($lng_mot>$lng_max) {
           // on decoupe
           $nb_f=($lng_mot/$lng_max)+1;
           $mot="";
           for ($j=0;$j<=$nb_f;$j++) {
               $mot.=substr($esp[$i],($j*$lng_max),$lng_max)." ";
           }
           $esp[$i]=$mot;
       }
       $tmp_txt.=$esp[$i]." ";
       $i++;
   }
   return $tmp_txt;
}

Cheers mate ...
 
WoozyDuck said:
Code:
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "<br>", 1);

it works good , but it will break all the words ! I just like to
break the long words !

Why not just use space or \n instead of <br>?
 
It doesnt work good
it still stretch the table
but Ive used the other function and it works perfect! ;)
 
Back
Top