Copy link to clipboard
Copied
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:
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>
Copy link to clipboard
Copied
Here's a function I use to strip HTML from content:
// match from
http://haacked.com/archive/2004/10/25/usingregularexpressionstomatchhtml.asp
x
var reTest =
"</?\w((\s\w(\s=\s(?:"".?""|'.?'|[^'"">\s]))?)+\s|\s)/?>"; //
"(...<a href="news/article.cfm?articleid=#GetArticles.ArticleID[variables.dis playRow]#">*Read more*</a>
</cfoutput
Copy link to clipboard
Copied
Your error was caused by not specifying the rownumber when setting the cleantext variable.
Copy link to clipboard
Copied
Thanks for the feedback, Dan and JMF,
I'm a CF amateur learning as I go along, so please excuse my ignorance. Dan, to define the rownumber in CleanText, I tried this line of code, but I received an error:
<cfset CleanText = REReplaceNoCase(GetPrayers.PrayerText, "</?[^>]*>", "", "all")[variables.displayRow]>
Could you show me how it should be? Also, then, when I go to output ShortText, the code will look like the following?
<cfset ShortText = left(CleanText, 200)>
<cfdump var="#ShortText#">
Thanks again.
Copy link to clipboard
Copied
Right variable, wrong place. You want queryname.fieldname[rownumber].
Copy link to clipboard
Copied
Got it! Thanks very much, Dan.