Jump to content

[SOLVED] Scrolling


jaymc

Recommended Posts

On my site I have a system where members can post comments on each others profiles

 

The problem Im having, if someone posts:

 

testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt

 

It will cause an x axis scroll bar because there is no break in the text

 

Whats the best way to combat this, Im assuming it has to be PHP as HTML will always stretch the content to fit it in, regardess of width specifications

 

I was thinkin of perhaps inserting an automatic <BR> after every 50th char, but the problem then it would cut genuine words in half if they fell into the 50th char

 

So I would need to make it  a bit more clever than that

 

Any help would be great!

 

Thanks

Link to comment
Share on other sites

Use:

 

wordwrap($text, 50, "<br />\n");

 

It won't split genuine words in half, unless you include the optional fourth parameter and set it to true... hope this helps

 

Ed

This only works with words

 

If someone just posts

 

tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt

 

It wont split it because that count as just one word

 

It will work if I add 'true' in the function but that of course will split genuine words in half

 

I think I need a way of detecting excesive letters

 

Its safe to say any word that contains more than 3 consecutive letters is not a valid word, e.g hellooooooooo

 

The CSS doesnt work either, it gives a scroll bar or still stretches the content, this cannot be

 

In Invision Power Board you can do it, here is how they describe it

 

Remove excess exclamation/question marks in topic titles?

Will turn: This!!!!! into This!

 

Any more suggestions?

Link to comment
Share on other sites

<?php

$test="testtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt";

if(strlen($test)>50){

$word=wordwrap($test,50,"<br>" ,true);
}
echo $word;

?>

Link to comment
Share on other sites

<?php

$test="testtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt";

if(strlen($test)>50){

$word=wordwrap($test,50,"<br>" ,true);
}
echo $word;

?>

Ok thats real good, however, to use that Im going to have to explode each comment by " " to dig out the words, then for each word do the strlen check

 

Sure it will work, but do I need to worry about it using a hell load of resources

 

The max amount of chars per comment is 1000

 

Its just my site is quite busy so the less resources my scripts use the better

 

Should I worry about it?

Link to comment
Share on other sites

have a look at this ok.

 


<?php

$test="testtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt";


echo "Total charecters ".strlen($test)." <br>";

if(strlen($test)>50){

$word=wordwrap($test,50,"<br>" ,true);
}
echo $word;

?>

Link to comment
Share on other sites

Heres what Ive come up with

 

$words = explode(" ", $comments[comment]);
$wordarray = array();

foreach ($words as $words) {

    if(strlen($words)>35){

$words=substr($words, 0, 35);


   }

$wordarray[] = $words;

}


$comments[comment] = join(" ", $wordarray);
[code]


Works a treat

[/code]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.