Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[PHP/HTML/CSS]Wordwrapping + Overflow problem.

Legendary Battlemage
Loyal Member
Joined
Apr 7, 2009
Messages
647
Reaction score
25


Yea...disaster.

I don't see what's wrong with my code

PHP:
			$posts = getPosts($id, $end, $start);

			while($nfo = mysql_fetch_array($posts))
			{
				$usernfo = getUserInfo($nfo['authorid']);

				echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" style=\"margin-bottom:5px; border-collapse:collapse; width:880px;\">";
				echo "<tr><td align=\"left\" valign=\"top\" class=\"postuserbox\">Author</td> <td align=\"left\" valign=\"top\" class=\"postprops\">";
				echo "<b>".$nfo['name']."</b> - Posted on ".$nfo['posted'];
				echo "</td></tr>";
				echo "<tr>";
				echo "<td align=\"left\" valign=\"top\" class=\"postuserbox\"> <div style=\"font-size:18pt;\">".$usernfo['name']."</div>".$usernfo['usertitle']."<br /><br /><div style=\"border:1px solid #000;\">Posts: ".getPostCount($usernfo['id'])."</div><div style=\"border:1px solid #000\">Joined: ".$usernfo['joindate']."</div><div style=\"border:1px solid #000;\">Location: ".$usernfo['location']."</div></td>";
				echo "<td align=\"left\" valign=\"top\" class=\"postbox\">";
				echo parseMessage($nfo['message']);
				if(strlen($usernfo['signature']) > 0)
				{
					echo "<br /><br /><br />";
					echo "<div class=\"signature\" style=\"clear: both; border-top: 1px solid #000; padding-top: 4px; width:75%;\">".$usernfo['signature']."</div>";
				}
				echo "</td></tr>";
				echo "</table>";
			}

CSS:
PHP:
.postuserbox {
	border:1px solid #000;
	width:220px;
}

.postprops {
	border:1px solid #000;
	width:660px;
}

.postbox {
	border:1px solid #000;
	width:660px;
	font-family:Tahoma;
	overflow:scroll;
}

.signature {
	width:100%;
	overflow:auto;
	padding-bottom:3px;
	line-height:1.3em;
}

But when the scrollbars come out, it only moves a bit, and the DIV is still expanded (as you can see in the link I provided above).


I also have another problem.
For displaying posts, I use these functions:
PHP:
function parseBBCode($message)
{
	//$message = wordwrap($message, 120, "<br />", true);

	#Lets use a regex instead of str_replace.#
	$message = preg_replace('|\[b\](.+?)\[\/b\]|i', '<b>$1</b>', $message);
	$message = preg_replace('|\[i\](.+?)\[\/i\]|i', '<i>$1</i>', $message);
	$message = preg_replace('|\[u\](.+?)\[\/u\]|i', '<u>$1</u>', $message);
	$message = preg_replace('|\[img\]http\:\/\/(.+?)\[\/img\]|i', '<img src="http://$1" border="0" alt="$1" title="$1">', $message);
	$message = preg_replace('|\[img\]ftp\:\/\/(.+?)\[\/img\]|i', '<img src="ftp://$1" border="0" alt="$1" title="$1">', $message);
	$message = preg_replace('|\[img\]svn\:\/\/(.+?)\[\/img\]|i', '<img src="svn://$1" border="0" alt="$1" title="$1">', $message);
	$message = preg_replace('|\[img\]https\:\/\/(.+?)\[\/img\]|i', '<img src="https://$1" border="0" alt="$1" title="$1">', $message);
	$message = preg_replace('|\[img\](.+?)\[\/img\]|i', '<img src="http://$1" border="0" alt="$1" title="$1">', $message);
	$message = preg_replace('|\[url="https\:\/\/(.+?)"\](.+?)\[\/url\]|i', '<a href="https://$1" target="_blank">$2</a>', $message);
	$message = preg_replace('|\[url="ftp\:\/\/(.+?)"\](.+?)\[\/url\]|i', '<a href="ftp://$1" target="_blank">$2</a>', $message);
	$message = preg_replace('|\[url="svn\:\/\/(.+?)"\](.+?)\[\/url\]|i', '<a href="svn://$1" target="_blank">$2</a>', $message);
	$message = preg_replace('|\[url="(.+?)"\](.+?)\[\/url\]|i', '<a href="http://$1" target="_blank">$2</a>', $message);
	$message = preg_replace('|\[color=(.+?[^;])\](.+?)\[\/color\]|i', '<font color="$1">$2</font>', $message);
	$message = preg_replace('|\[size=(.+?[^;])\](.+?)\[\/size\]|i', '<font size="$1">$2</font>', $message);
	$message = preg_replace('|\[center\](.+?)\[\/center\]|i', '<center>$1</center>', $message);
	$message = preg_replace('|\[code\](.+?)\[\/code\]|i', '<div style="border:1px solid #FFF; overflow:auto; width:500px; color:green;"><font size="5" color="#FFF" style="border-bottom:1px solid #FFF;">Code:</font>$1</div>', $message);
	$message = preg_replace('|\[strike\](.+?)\[\/strike\]|i', '<strike>$1</strike>', $message);

	return $message;
}

function parseMessage($message)
{
	return parseBBCode(nl2br(strip_tags(stripslashes($message))));
}

As you can see, I commented out the wordwrap function, since it was ruining my HTML code.

Basically, if I kept typing in BBCode, by the end of 120 characters, it would automatically add a < br />

So for example, if i kept typing in [ img]link[ / img]

it would go

Code:
< img src="link">< img src="link">< img src="link">< img src="link">< img src="link">< img src="link">< img src="lin<br />k">

Which of course, changed the link, causing the images not to display.

I know that the final parameter, cut of wordwrap allows you not to cut if there is a word, but that won't work either, seeing that a person could just type a letter forever.

Any help is appreciated. :)
 
Joined
Sep 10, 2006
Messages
2,817
Reaction score
1,417
Overflow won't work for TDs apparently, and you shouldn't use tables at all, you can either wrap it in a div and give that div overflow: auto and width or you could do what's vB doing, write a function that adds a space once the word is longer than x letters.

As for BB thing, I belive you should add to db already parsed to html, imagine 1500 people looking at thread with 20 replies on one page each including at least one BB thing, that's alot of stress I'd say, but not sure about it at all.
 
Joined
Jun 8, 2007
Messages
1,985
Reaction score
490
I'd suggest storing two copies of content. One in BBcode for reference later, and one in HTML for output. The reason for the BBcode backup is in case you update your BBcode->HTML converter, you can update the existing posts that had errors. Also, if someone abuses your forum with an XSS injection, when you fix it you can convert the BBcode to HTML without much effort.

You definitely don't want to run the conversion on every page-load, that's very inefficient.
 
Last edited:
Legendary Battlemage
Loyal Member
Joined
Apr 7, 2009
Messages
647
Reaction score
25
Thanks, I'll just add two fields:
raw_content and html_content.

But what about my second problem?
 
Back
Top