Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Getting Started / January 2007



Tip: Looking for answers? Try searching our database.

Decoding Special Characters...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AppDeveloper - 27 Jan 2007 00:43 GMT
Hi All,

I have some raw data coming from a column in a database that contains the
following data (code):

<table cellspacing="0" border="0" cellpadding="0" width="100%"
bgcolor="white"><tr><td width="30%">&amp;nbsp;</td><td
width="70%">&amp;nbsp;</td></tr><TR><TD><font face="arial"
size="2"><b>Name:</b></font></TD><<TD><font face="arial"
size="2"><b>Email:</b></font></TD>  (bla, bla, bla and so on...)

Unfortunately, when I query the data and output it, it returns (outputs) the
following:

<table cellspacing="0" border="0" cellpadding="0" width="100%"
bgcolor="white"><tr><td width="30%"></td><td
width="70%"></td></tr><tr><td><font face="arial"
size="2">[B]Name:[/B]</font></td><<td><font face="arial"
size="2">[B]Email:[/B]</font></td> (bla, bla, bla and so on...)

I've tried to use the URLDecode function to decode it but doesn't work.  Is
there a way or a CF function that I can use to convert these special charaters,
"<", ">", "&amp;nbsp;" to " < ", " > ", "&nbsp;"  respectively without using
the ReplaceNoCase function which is what I'm doing now (see below):

<CFSET HTML_Content = Trim(GetHTMLContent.HTML_Content)>
<CFSET HTML_Content = ReplaceNoCase(HTML_Content,"<","<","ALL")>
<CFSET HTML_Content = ReplaceNoCase(HTML_Content,">",">","ALL")>
<CFSET HTML_Content = ReplaceNoCase(HTML_Content,"&amp;##39;","'","ALL")>
<CFSET HTML_Content = ReplaceNoCase(HTML_Content,"&amp;nbsp;","&nbsp;","ALL")>
<CFOUTPUT>#HTML_Content#</CFOUTPUT>

Many thanks in advance!
BKBK - 27 Jan 2007 11:01 GMT
http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000506.htm

<cfset rawData='&lt;table cellspacing="0" border="0" cellpadding="0"
width="100%" bgcolor="white"&gt;&lt;tr&gt;&lt;td
width="30%"&gt;&amp;nbsp;&lt;/td&gt;&lt;td
width="70%"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;TR&gt;&lt;TD&gt;&lt;font
face="arial"
size="2"&gt;&lt;b&gt;Name:&lt;/b&gt;&lt;/font&gt;&lt;/TD&gt;&lt;&lt;TD&gt;&lt;fo
nt face="arial" size="2"&gt;&lt;b&gt;Email:&lt;/b&gt;&lt;/font&gt;&lt;/TD&gt;
(bla, bla, bla and so on...)'>
 <p>
 <strong>without htmlEditFormat:</strong><br>
 <cfoutput>#rawData#</cfoutput>
</p>
<strong>with htmlEditFormat:</strong><br>
 <cfoutput>#htmlEditFormat(rawData)#</cfoutput>
AppDeveloper - 29 Jan 2007 21:49 GMT
Hi BKBK,

Your suggestion is not working. Any other advice?

Many thanks!
BKBK - 30 Jan 2007 05:54 GMT
Copy-and-paste the code I've given, and save it as [i]entityTest.cfm[/i]. Run it and you will find that it works.
AppDeveloper - 30 Jan 2007 19:55 GMT
Hi BKBK,

I copied your code and ran it, but it shows this "<table cellspacing="0"
border="0" cellpadding="0" width="100%" bgcolor="white"><tr><td
width="30%">&nbsp;</td><td width="70%">&nbsp;</td></tr><TR><TD><font
face="arial" size="2">[B]Name:[/B]</font></TD><<TD><font face="arial"
size="2">[B]Email:[/B]</font></TD> (bla, bla, bla and so on...) " when running
it on the browser.  I want the code rendered out as an html page with 2 columns
"Name" and "Email" in a table.

Thanks.
BKBK - 30 Jan 2007 21:24 GMT
It wasn't clear to me you wanted to produce a table. Here then is an idea

<cfset rawData='<table cellspacing="0" border="1" cellpadding="0" width="100%"
bgcolor="white"><tr><td width="30%">&amp;nbsp;</td><td
width="70%">&amp;nbsp;</td></tr><TR><TD><font face="arial"
size="2"><b>Name:</b></font></TD><TD><font face="arial"
size="2"><b>Email:</b></font></TD></TR></table> '>
<cfset rawData = replaceNoCase(rawData,"<","<","all")>
<cfset rawData = replaceNoCase(rawData,">",">","all")>
<cfset rawData = replaceNoCase(rawData,"&amp;","&","all")>

<cfoutput>#rawData#</cfoutput>
[CJ] - 31 Jan 2007 00:54 GMT
as far as i know, there's no built in function to unescape the escaped HTML
characters.

i think your replace() functions will be the way to go.  I know it's not
pretty...but you could always just wrap that into a UDF so at least it's
modular.
BKBK - 31 Jan 2007 06:22 GMT
AppDeveloper, I realize just now that what you had done [i]did work[/i], and
you were only looking for an alternative. I missed your point right from the
beginning. Sorry about that. As they say, when one picks the wrong branch at a
junction, any further step only  takes one further away from one's destination.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.