Jump to content


Photo

word wrap..


  • Please log in to reply
5 replies to this topic

#1 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 29 May 2006 - 06:48 PM

is there any way that i can word wrap when someone puts in more than the td can handle on width..

beacuase if i gave a person a limit width to write and they write one long word together the td just expands to try and fit it all..

is there any way that i can use something to say on how many charaterc to cause a line breake..

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 29 May 2006 - 07:26 PM

wordwrap() function

$text = 'supercallifragilisticexpiallidocious is a good word to test wordwrap function';

$width = 20;

echo wordwrap($text,$width,'<br/>',1);

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 29 May 2006 - 07:53 PM

add that was easier than i ha din mind.. thanx..

oh but the bad thing is that it wraps every x number no matter what..ever if the word doesn't tke the spot and its the x number it wraps.. can there be any way to use it only if one word take more than it supossed to?

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 29 May 2006 - 08:12 PM

You would have to to get the word lengths and check them to see if the max length was exceeded

function max_word($text) {
    $words = explode(' ',$text);
    foreach($words as $w) {
        $sizes[] = strlen($w);
    }
    return max($sizes);
}

$text = 'supercallifragilistic expiallidocious is a good word to test wordwrap function';

$width = 20;

if (max_word($text) > $width)
    echo wordwrap($text,$width,'<br/>',1);
else
    echo $text;

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 29 May 2006 - 08:54 PM

nice. but one more thing if i put it in the text that it's ben out put it litterary puts out the <br> so everyone can see there is a br..so should i do the function before the text goes in to the database?

#6 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 29 May 2006 - 09:05 PM

Don't store text with '<BR>' in the database. Do the formatting on output.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users