How to wrap long text strings, as in a URL.

Dr. GBooky is here to help you with your guestbook problems ...
Post Reply
noisenet
Posts: 5
Joined: Mon Jan 16, 2006 3:33 am

How to wrap long text strings, as in a URL.

Post by noisenet »

Script URL: http://www.nineyearsunder.com/main.html
Version of script: Version: 1.34
Version of PHP: PHP Version 4.3.11
Hosting company: Unknown
Have you searched THIS FORUM for your problem: Yes
(if not please do before posting)
If so, what terms did you try: text string, URL, wrap

Write your message below:
First, I used the main page in the URL above because it is a framed site and I have it scripted so that if someone accesses any of the pages without the frameset, it automatically redirects to the main.html file. So at this URL, just click the "Board" menu item.

The question is this - when a guest visits and enters their website URL, if it is a long URL, the string will not wrap to a new line which, in turn, blows the TD widths, causing the comments cell to be crammed and hard to read. I have tried specifying exact pixel values for the cells as well as a few PHP wrap functions I've found online. But since I'm very inexperienced with PHP (or any real programming syntax), I've not been able to figure out how to implement it.

Thank you in advance for your assistance and your fine library of scripts.

Steve
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Post by Henrie »

Hello Steve,

I have two solutions for you.

1. The most easy one is to add the following to the table.entries style in the file style.css

Code: Select all

table-layout:fixed;
The style will now look like this.

Code: Select all

table.entries {
	color : black;
	font-family : Verdana, Geneva, Arial, Helvetica, sans-serif;
	font-size: 11px;
	BORDER-RIGHT: #23559C 1px solid;
	BORDER-LEFT: #23559C 1px solid;
	BORDER-TOP: #23559C 1px solid;
	BORDER-BOTTOM: #23559C 1px solid;
	table-layout:fixed;
}
This will prevent long words (and url's) to mess up the layout.
A disadvantage is that a long url is displayed behind the comments text.

2. Edit some code in the GBook.php file
Change line 565 (Gbook version 1.34)

Code: Select all

echo '<a href="go.php?url='.$url.'" target="_blank" class="smaller">'.$url.'</a>';
to

Code: Select all

$url2 = wordwrap($url, 18, "\n", 1);
echo '<a href="go.php?url='.$url.'" target="_blank" class="smaller">'.$url2.'</a>';
You can enter the number of characters after which a break is inserted by changing 18 to your desired number.
Disadvantage of this method is that it breaks exactly after the number of characters so a word can be broken in the middle.

You can also use both methods at the same time.

Greetings,
Henrie
Post Reply