From: kenji776 on
Hey everyone. I have a many parts in my site where users can enter text that
users can read later, like weblogs, articles, rants and so on. I want to have
some special commands such as turning :) into a smily face, or turning (TAB)
into an actual tab, or turning the ascii char 13 (The ascii char for line
break) into a <BR /> It would in essense be a collection of replace statments,
that is the easy part. What I want to do is write one function that can be
called and returns the "parsed" text. I have never created a function that
takes in info and returns new info. I am pretty sure it is going to be a .cfc.
Would someone be kind enough to perhaps create a very small function that would
intake a variable, and show me how to return it to the caller. Like this...

User inputs text--->Page takes text and inserts into database--->another user
goes to view--->text is first sent to formatting function--->formatted text is
given to calling page--->formatted text is displayed.

I hope this all makes sence. I will include the first few replace statments
that I would want in this function.


<!--- These replace statments do some basic formatting, getrants is just the
name of the query this text was copied from-->

<!---If the user types (TAB) in their text, it replaces that with 5 spaces for
easy tabbing of text------------->
<cfset getrants.message =
#Replace(getrants.message,"(TAB)","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;","all")#>

<!---Replaces all line breaks that are put in the text area with html <br>
tags so text it outputted the way the user entered it in the first place.--->
<cfset getrants.message =
#Replace(getrants.message,"#chr(10)#","<br>","all")#>

<!------If a user types (SPACE) in their text, it lets them easily add extra
spaces---------------->
<cfset getrants.message =
#Replace(getrants.message,"(SPACE)","&nbsp;","all")#>

<!---- Down here would be some more code for replacing :) with a smily face
image and :( with a frownie face, and so on.--->

From: Dan Bracuk on
Visit cflib.org and download the safetext function. Read the source code. That will give you a general idea of what to do.
From: kenji776 on
Okay, I got my own function up and running. However I am having some problems
with this line
theText = #Replace(theText,":)","<img
src="IMG\Emotes\icon_biggrin.gif">","all")#;

It keeps erroring on that line saying...

Invalid CFML construct found on line 8 at column 48.
ColdFusion was looking at the following text:

IMG

The CFML compiler was processing:

* an expression beginning with "#", on line 8, column 13.This message is
usually caused by a problem in the expressions structure.
* a script statement beginning with "theText" on line 8, column 3.
* a script statement beginning with "function" on line 2, column 1.
* a cfscript tag beginning on line 1, column 2.


The error occurred in D:\FTP\Digital Swordsmen\Prod\Parsetext.cfm: line 8

I don't know what to do, I can't seem to use escapes to fix it or anything. I
don't know what t do, attatched is the full code for my function.

<cfscript>
function parsetext(text)
{
var theText = trim(text);
theText = #Replace(theText,"(TAB)","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;","all")#;
theText = #Replace(theText,"#chr(10)#","<br>","all")#;
theText = #Replace(theText,"(SPACE)","&nbsp;","all")#;
theText = #Replace(theText,":)","<img
src="IMG\Emotes\icon_biggrin.gif">","all")#;
return theText;
}
</cfscript>

From: Dan Bracuk on
You have nested quotes. Make the inside ones single quotes. In other words,
change this:
theText = #Replace(theText,"","<img
src="IMG\Emotes\icon_biggrin.gif">","all")#;
to this
theText = #Replace(theText,"","<img
src='IMG\Emotes\icon_biggrin.gif'>'","all")#;


From: kenji776 on
Thanks so much, that worked like a charm. Its funny that the single quotes make
it work, I was gonna try that last night, then I was just like "It would just
be another wasted attempt, you've already tried like 50 things, you might as
well just post on the forums". cool though, thanks again, my function is
working awsomly now.

 | 
Pages: 1
Prev: cfmail
Next: Could not generate Stub Objects