Web Hosting Talk







View Full Version : how can i stop pages from being stretched?when someone posts something in my shoutbox


mikey1090
11-06-2006, 01:35 PM
when someone posts something in my shoutbox, if they post a huge long word with no spaces, it stretches the page. is there a way with css/php that i can prevent it?

mwatkins
11-06-2006, 02:04 PM
Read up on CSS, specifically the "overflow" attribute. Use hidden or "auto".

mikey1090
11-06-2006, 02:06 PM
i am currently using auto overflow, i just wondered if there was another alternative...so you dont need to scroll across.

mwatkins
11-06-2006, 02:36 PM
Ah, well if you've already been down that road, then your next step is to look at hyphenation. CSS can't do that for you of course, which means you need to parse the text and break very long word strings up at boundaries, or wrap the text just before, which you'll have to determine based on width of the container (div, textbox, etc). Not trivial.

Alternatively you could do a really quick hack and insert a newline or br (depending on whether its formatted or pre/code text) just before any very long string. Not very sophisticated but...

spasticus
11-06-2006, 02:40 PM
i thought shoutboxes automatically split or ingnored long words? maybe you use a different one to the one ive seen - any way...

if you add this - or something like this to the page which proccess the message it should do what you want. change the 20 to however many characters wide you shoutbox is.

<?php

$text = "realyrealyrealyrealylongmessage"; //this is the message the user enters
$newtext = wordwrap($text, 20, " ", 1); //split the text after every 20 characters - seporate with a space

echo "$newtext"; //display the message

?>

Adam-AEC
11-06-2006, 02:52 PM
I wonder if the max-width CSS attribute would work in this case?

I'm no CSS expert tho.

mikey1090
11-07-2006, 12:40 PM
spasticus


THAT was exactly what i needed

thankyou very much:D :)