File Editing - Part 2

Ryan Chong
Ryan Chong used Ask the Experts™
on
Hi,

The idea is try save the HTML in a txt file, then load it into a page.

But, from the code below, if you try enter more that 1 line, you will find the problem that the content will be lenghten in line count > that's add a new line when a {Enter} is key in in the content.

Please try test the code below and you'll know what is the problem. Can this be resolve easily? Thanks.

<cfapplication name="oxel" sessionmanagement="Yes" setclientcookies="Yes">
<cfinclude template = "checklogin.cfm">

<cfset dir = GetDirectoryFromPath(getTemplatePath())>    
<cfset dir = dir & "newsflicker.txt">

<cfif Not FileExists(dir)>
     <cflocation url = "error.cfm?error=5">
</cfif>

<cfset filecontent = "">
<cfset msg = "">

<cfif isDefined("form.Submit")>
     <cfFile Action = "Write" File = #dir# output = "#Trim(form.content)#">
     <cfset msg = "News Flicker Updated<br>">    
</cfif>

<cfFile Action = "Read" File = #dir# Variable = "filecontent">

<html>
<head>
<title>Oxel Admin Console</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="500" border="0">
  <tr>
    <td width="365"><a href="home.cfm">Home</a></td>
    <td width="125">
      <div align="right"><a href="logout.cfm">Logout</a> | <a href="help.htm">Help</a></div>
    </td>
  </tr>
</table>
<cfoutput>#msg#</cfoutput>
<form name="form1" method="post" action="newsflicker.cfm">
  <table width="500" border="0">
    <tr>
      <td>News Flicker Content</td>
    </tr>
    <tr>
      <td>
        <textarea name="content" cols="50" rows="10"><cfoutput>#filecontent#</cfoutput></textarea>
      </td>
    </tr>
    <tr>
      <td>
        <input type="submit" name="Submit" value="Save">
        <input type="reset" name="Submit2" value="Reset">
      </td>
    </tr>
  </table>
</form>
</body>
<head>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
</head>
</html>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead

Author

Commented:
What is the {Enter} key in Coldfusion?

Example:

In vb = vbcrlf
In java = \n

thanks
Ryan ChongSoftware Team Lead

Author

Commented:
Problem resolved.

<cfset fcontent = "#HTMLEditformat(form.content)#">

Thanks. I will delete this question soon.

Commented:
i think chr(13) is the enter key
Expert Spotlight: Joe Anderson (DatabaseMX)

We’ve posted a new Expert Spotlight!  Joe Anderson (DatabaseMX) has been on Experts Exchange since 2006. Learn more about this database architect, guitar aficionado, and Microsoft MVP.

Ryan ChongSoftware Team Lead

Author

Commented:
Hi dash420,

Thanks for the help, i have a problem here, if you can solved it the points is yours.


I try to read a content from a file by using:

<cfset arr = ListToArray(JSStringFormat(HTMLEditFormat(filecontent)),chr(13))>


The file contains the HTML code as follows:

<b>HIGHLIGHT OF THE SINGAPORE MOTORSHOW 2002, 15-24 NOV AT SUNTEC SINGAPORE</b><br><a href=news.htm>Click here to read more</a>
<b>OPEL VECTRA NAMED BEST MID-SIZED CAR IN NEWSPAPER COMPETITION (8/11/2002)</b><br><a href=news2.htm>Click here to read more</a>
<b>AUTO EUROKARS IS THE NEW OPEL PASSENGER CAR DEALER IN SINGAPORE</b>
<b>TRIANGLE AUTO IS THE NEW OPEL COMMERCIAL VEHICLE DEALER IN SINGAPORE</b>
<b>OFFICIAL OPENING OF THE AUTO EUROKARS SHOWROOMS AT 5 UBI CLOSE AND 23 LENG KEE ROAD ON 11 NOV 2002</b>
<b>LAUNCH OF THE NEW VECTRA AT AUTO EUROKARS@UBI ON 11 NOV 2002</b>

I try to split them into an array, but all the content still not being splited.
Ryan ChongSoftware Team Lead

Author

Commented:
Basically, i want to split the text file content into an array. i try use:

<cfset arr = ListToArray(JSStringFormat(HTMLEditFormat(filecontent)),"\n")>

before, but it do a split near the "n" in "... href=news.htm> ... " :(

Any comments?

Commented:
Hi,

Ask the site moderator to remove this q's from the forum & refund u ur q's points

K'Rgds
Anand
Commented:
listto array will not work. as it does not find any comma in the text it will consider the text as list.

just try this
contain  of the "test.txt"
----
<b>HIGHLIGHT OF THE SINGAPORE MOTORSHOW 2002, 15-24 NOV AT SUNTEC SINGAPORE</b><br><a href=news.htm>Click here to read more</a>
<b>OPEL VECTRA NAMED BEST MID-SIZED CAR IN NEWSPAPER COMPETITION (8/11/2002)</b><br><a href=news2.htm>Click here to read more</a>
<b>AUTO EUROKARS IS THE NEW OPEL PASSENGER CAR DEALER IN SINGAPORE</b>
<b>TRIANGLE AUTO IS THE NEW OPEL COMMERCIAL VEHICLE DEALER IN SINGAPORE</b>
<b>OFFICIAL OPENING OF THE AUTO EUROKARS SHOWROOMS AT 5 UBI CLOSE AND 23 LENG KEE ROAD ON 11 NOV 2002</b>
<b>LAUNCH OF THE NEW VECTRA AT AUTO EUROKARS@UBI ON 11 NOV 2002</b>
---

<cfoutput>
<cfset dir = GetDirectoryFromPath(getTemplatePath())>    
<cfset dir = dir & "test.txt">

<cfFile Action = "Read" File = #dir# Variable = "filecontent">
<cfloop index="rc" list="#filecontent#" delimiters="#Chr(13)#">
   #rc#<br>
</cfloop>

</cfoutput>
Ryan ChongSoftware Team Lead

Author

Commented:
Sorry, problem resolved again:

<cfset filecontent = "">
<cfset dir = GetDirectoryFromPath(getTemplatePath())>    
<cfset dir = dir & "admin\newsflicker.txt">

<cfif FileExists(dir)>
     <cfFile Action = "Read" File = #dir# Variable = "filecontent">
</cfif>
<cfset filecontent = #Replace(HTMLEditFormat(JSStringFormat(filecontent)),"\r\n", "$$","All")# >
<cfset arr = ListToArray(HTMLEditformat(JSStringFormat(filecontent)),"$$")>

<cfloop index = "cnt" from = "1" to = "#ArrayLen(arr)#">
     <cfset dis = #Replace(arr[cnt], "&lt;", "'", "All")# >
     <cfset dis = #Replace(dis, "&gt;", "'", "All")# >
     <cfset dis = #Replace(dis, "&amp;lt;", "<", "All")# >
     <cfset dis = #Replace(dis, "&amp;gt;", ">", "All")# >
     <cfset dis = #Replace(dis, "&quot;", "'", "All")# >
     <cfset dis = #URLDecode(dis)#>
     <cfoutput>myScroller1.addItem("#dis#");</cfoutput>
</cfloop>

However, the code looks bad, if someone can amend it to be better then this question will be yours. Thanks
Ryan ChongSoftware Team Lead

Author

Commented:
Hi dash420,

<cfloop index="rc" list="#filecontent#" delimiters="#Chr
...
</cfloop>

after this, how can i get the content in list ?

Commented:
you can store each line of file content to the list. as each times in the loop contains one line.

regards,
Dash
Ryan ChongSoftware Team Lead

Author

Commented:
>>you can store each line of file content to the list. as each times in the loop contains one line.

Yes, but how can i do that?

<cfloop index="rc" list="#filecontent#" delimiters="#Chr(13)#">
    <cfset dis = #ListGetAt("#filecontent#", rc, "#Chr(13)#")#>
    <cfoutput>#dis#</cfoutput>
</cfloop>

The code above is not working at ListGetAt .. so to solve this? thanks.
Ryan ChongSoftware Team Lead

Author

Commented:
But this is working:

<cfset dis = #ListGetAt("#filecontent#", 1, "#Chr(13)#")#>

why?

Commented:
since listGetAt will find the list at particular position. so second argument should be integer that from which position we want the list.
just try this
<cfFile Action = "Read" File = #dir# Variable = "filecontent">
<cfloop index="rc" list="#filecontent#" delimiters="#Chr(13)#">
  <cfset dis = #ListGetAt("#rc#", 1, "#Chr(13)#")#>

#dis#<br>

</cfloop>


Commented:
ryancys is there any progress.

Commented:
Setting it to an array is faster.  Long lists makes for slow processing times.  DRE
Ryan ChongSoftware Team Lead

Author

Commented:
dash,
Still the same, i need change this:
<cfset dis = #ListGetAt("#rc#", 1, "#Chr(13)#")#>
so that the the second orguement is changeable.

it404,
Any code to share here?

What have done so far:

<cfset filecontent = "">
<cfset dir = GetDirectoryFromPath(getTemplatePath())>    
<cfset dir = dir & "admin\newsflicker.txt">

<cfif FileExists(dir)>
    <cfFile Action = "Read" File = #dir# Variable = "filecontent">
</cfif>


<cfset cnt = 0>
<cfloop index="rc" list="#filecontent#" delimiters="#Chr(13)#">
     <cfset cnt = cnt + 1>
     <cfset dis = #ListGetAt("#filecontent#", cnt, "#Chr(13)#")#>
     <cfset dis = #Replace(JSStringFormat(dis), "&lt;", "'", "All")# >
    <cfset dis = #Replace(dis, "&gt;", "'", "All")# >
    <cfset dis = #Replace(dis, "&amp;lt;", "<", "All")# >
    <cfset dis = #Replace(dis, "&amp;gt;", ">", "All")# >
    <cfset dis = #Replace(dis, "&quot;", "'", "All")# >
     <cfset dis = #Replace(dis, "\\r", "\r", "All")# >
     
     <cfoutput>myScroller1.addItem("#dis#");</cfoutput>
</cfloop>

Stupid solution, right?!

Commented:
R, I'm having a hard time understanding what youre doing?  So, if I get it, you've got an html formatted string that can kinda look like a list if you think of the returns as the ends of the list items.  you want to strip the html, then, seperate each line into a cf array, the loop the array into some javascript that builds a js array for some sort of scroller?  If thats right, I'll write some psuedo code for you.  DRE

Commented:
it is really funny.
Ryan ChongSoftware Team Lead

Author

Commented:
Any code that amend the last post on 11/19/2002 05:02PM PST will be fine. thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial