Outputting clean, random text
Hi all,
On the homepage of my Web site, I have an area where part of an article displays with a link to the full article text. The article that is loaded is random (base don the code below), and limited to a 200-character output. Now, some of my articles have simple HTML tags in them like break and paragraph. What I'm trying to do with the following script is:
- select a random article from the query
- strip it of HTML tags (I don't want the formatting preserved in the article preview, but I do want it preserved for the full text)
- output only 200 characters.
- link to the full article text
When I try the method below, I get the "You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members" error. Can someone help clear this up for me? Thank you!
<cfquery name="GetArticles" datasource="DS">
SELECT ArticleID,ArticleText,Active
FROM News
WHERE Active = -1
ORDER BY ArticleID
</cfquery>
<cfoutput>
#Dateformat(Today, "mmmm d, yyyy")#</strong><br />
<cfset displayRow = randRange(1, GetArticles.recordCount)>
<cfset CleanText = REReplaceNoCase(GetArticles.ArticleText, "</?[^>]*>", "", "all")>
<cfset ShortText = left(CleanText, 200)>
<cfdump var="#ShortText[variables.displayRow]#">...<a href="news/article.cfm?articleid=#GetArticles.ArticleID[variables.displayRow]#"><strong>Read more</strong></a>
</cfoutput>
