Jump to content

Archived

This topic is now archived and is closed to further replies.

corillo181

word wrap..

Recommended Posts

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..

Share this post


Link to post
Share on other sites
wordwrap() function

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

$width = 20;

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
You would have to to get the word lengths and check them to see if the max length was exceeded

[code]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;
[/code]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Don't store text with '<BR>' in the database. Do the formatting on output.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.