[ic] return section of text that contain search term
Jerry
interchange-users@icdevgroup.org
Thu Jan 2 14:47:00 2003
> I would like to return a section of text in context around a
> search term. I am wondering if anyone has done this. I
> could have sworn I had seen something like this before on
> an earlier version of the ICDEV site, but maybe not. What
> I am going for is something similar to what Google does
> on their results, only not as jazzy -- I just do not want to
> return the whole db value as it may be quite long ....
>
> Has anyone done this? Any ideas on it? input? direction?
Assuming you are returning something like [item-description] from
your search. Something like this would work if I understand your
question correctly.
[calc]
# Set the maximum length of the string you want to display
$max_length = 25;
$out = q{[item-description]};
if (length($out) > $max_length) {
$out = substr($out,0,$max_length);
# In case we chopped up a word, backup to the last space
$out =~ s/ [^ ]*$//;
# add some ... to the end of the string
return $out . " ...";
}
return $out;
[/calc]
Think this is what you want...
Jerry