Gossamer Forum
Home : Products : DBMan : Customization :

Shorten Displayed Text

Quote Reply
Shorten Displayed Text
Hi

I set up a searchable database about a year ago using JPDeni's great advice and all has run well. Now I have a problem that I can't seem to solve. Any advice will be much appreciated.

The last field displayed on my results page is a url. Up to now the lenghth of this has not been a problem but due to changing circumstances the url can be up to 400 characters and completely messes up the displayed results.

I believe this can be solved by in html_record but can't work out quite how. The field I want to shorten the display of is 'J'. Here's my script for html_record:

sub html_record {
# --------------------------------------------------------
# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.

my (%rec) = @_; # Load any defaults to put in the VALUE field.

my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2';


$url{'J'} = $rec{'J'};
$url{'J'} =~ s/<\/?B>//g;


# Replace FieldName below with the names of the fields you want to display. Create as many table cells as you wish, one for each field.
print qq|
<TD BORDER=1 BGCOLOR="#FFFFCC">&nbsp;<$font>$rec{'B'}</Font></TD><TD BORDER=1 BGCOLOR="#FFFFCC">&nbsp;<$font>$rec{'E'}</Font></TD>
<TD BORDER=1 BGCOLOR="#FFFFCC">&nbsp;<$font>$rec{'F'}</Font></TD><TD BORDER=1 BGCOLOR="#FFFFCC">&nbsp;<$font>$rec{'G'}</Font></TD>
<TD BORDER=1 BGCOLOR="#FFFFCC">&nbsp;<$font>$rec{'H'}</Font></TD><TD BORDER=1 BGCOLOR="#FFFFCC">&nbsp;<$font><a href="$url{'J'}">$rec{'J'}</TD> |;

}

Thanks in advance.
Andy
Quote Reply
Re: [AndyOops] Shorten Displayed Text In reply to
Piece o' cake!! :-)

After

Code:

$url{'J'} =~ s/<\/?B>//g;


Add

Code:

if (length($rec{'J'}) > 20)
{
$rec{'J'} = substr($rec{'J'},0,10) . " ... " . substr($rec{'J'},-10);
}


If your value has more than 20 characters, it will only print out the first 10, a "..." and the last 10, but the URL will be intact. It should also maintain the bolding if there is any, although the bold tags will be included in the character count.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Shorten Displayed Text In reply to
Brilliant. Worked instantly.

Thanks JP
Smile