Jump to content

[SOLVED] Removing excessive newlines and breaks


NottaGuru

Recommended Posts

I 'think' this can be done...

 

I am creating a message board and need some serious help.

 

The scenario...

A user enters a message and I use the nl2br function to keep the formatting...

 

Now the message is displayed...

I use substr to limit the displayed text to 165 characters

 

The problem...

I have a height limit of 100 px each for displaying the last 3 messages but if a user enters 10 lines with just the letter 'a', that is only counted as 10 characters, but the message is 10 lines tall and breaks the layout. Is there a way to stop this? I tried using CSS to limit each 'Message' to 100px, but no luck.

 

The solution...

I dunno.

lets say you are using 12px font. That gives you a maximum of 8 lines that a user can have before they are breaking the 100px height limit.  With that known, you know their message cannot be more than 8 lines.  I would gladly help you further, but to do so, I'd need to see how you are currently doing the calculation, so I can help you figure out how to do it better.

I tried the example above both as the first code to process the displayed message and also as the last code.

 

I need the message to be the original message for when a user reads the whole message. I need help with the displayed partial message.

 

Here is the relevant code...

 

Form submitted...

$NewMessage=htmlentities($_POST[NewMessage]);
$NewMessage=nl2br($NewMessage);

 

If no errors (blank form, unacceptable words, etc), message entered into a mysql table.

 

The display...

Info drawn from the table and shown on the screen in a while loop because only showing last 3 messages.

 

// 165 characters per message
$Message=substr($messagerow[Message],0,165);

if(strlen($messagerow[Message])>165)
{
$Message.=".....";
}

 

<p class='message'><a href='' title=''>$Message</a></p>

 

The CSS...

#message_board_container div.message {
padding: 0 0 0 2px;
width: 210px;
height: 100px;}

 

For the CSS, I've used height, max-height, and min-height and max-height both.

 

When the user enters a message with 10 new lines of 1 character each, that is 10 characters and shown as 10 lines because it does not meet the 165 character length. What happens is the extra lines bleed down in to the next message.

Archived

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

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