Guestbook Formatting Help

Soldato
Joined
11 Apr 2003
Posts
4,210
Location
Notts
Hi all, I have my guestbook working as I wish, all bar one thing:

If anyone inserts a continual line such as "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

The page breaks, in order to stop this I have used the following code:

Code:
<?php
					}
					else
					{
						// get all guestbook entries
						while($row = mysql_fetch_array($result))
					{
					// list() is a convenient way of assign a list of variables
					// from an array values 
					list($id, $user, $title, $message, $date) = $row;

					// change all HTML special characters,
					// to prevent some nasty code injection
					$title    = htmlspecialchars($title);
					$user    = htmlspecialchars($user);
					$message = htmlspecialchars($message);
					
					//Adds Spacing To Stop Page Breaking	
					$title = chunk_split($title,40," ");
					$user = chunk_split($user,40," ");
					$message = chunk_split($message,40," ");	

					// convert newline characters ( \n OR \r OR both ) to HTML break tag ( <br> )
					$message = nl2br($message);
				?>

However this leaves me with odd looking sentences E.G

upd ate more :D
and tha t could be a shame
need t o appreciate

Therefore I was just wondering if anyone would be able to help me create a piece of code that would prevent the page from breaking, but not cause me to have random spaces in messages?

Thanks all,
Jcb33.
 
Code:
$text = preg_replace("/(\S{40})/", "$1 ", $text);

(You should probably add some way to stop this breaking URLs, or better yet do what vB/other forums do and automatically linkify them, then trim them, then run this.)
 
Back
Top Bottom