This will trim the text (str) at the specified length (trimat) and then
delete everything AFTER the last space it finds. This way no words get cut
in half. This is a much scaled down version of what I use for 'teasers' to
articles. This method simply removes html rather than take them in to
account when trimming the length.
<cfscript>
function teaserText(str,trimat)
{
if(len(str) gt trimat)
{
// Remove any html tags so they arent counted in the length
str = rereplace(str, "<.*?>", "", "all");
//Cut the text at the desired length
str = left(str, trimat);
//Delete everything after the last space character
str = listdeleteat(str, listlen(str, " "), " ");
//Add '...' to the end to indicate that there is more to
//read than what you see here
str = str & "...";
}
return str;
}
</cfscript>
<cfoutput>#teasertext(thetext, 150)#</cfoutput>
-----Original Message-----
From: terry yee [mailto:[EMAIL PROTECTED]
Sent: Sunday, October 08, 2006 5:36 PM
To: CF-Talk
Subject: limiting output of text
Hi,
Am calling text from datasource and need to display only a small portion of
it. ie. first 100 characters etc..
my code:
<cfif len(getRewards.reward_description)>
#Replace(Trim(getRewards.reward_description), Chr(10), "<br> " ,
"ALL")# </cfif>
cheers
terry
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four
times a year.
http://www.fusionauthority.com/quarterly
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:255943
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4