Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1124
  • Last Modified:

Coldfusion - New Line without using <br>

Hello experts
I have a function to create a part of my htaccess file.
I'm using the following code:
<cffunction name="fwriteurlcategories" access="private" returntype="void">
  <!--- Get information from categories table--->
  <cfset var getcategories = fcategories()>
  <cfoutput query="geturlrwcategories">
   <cfset newline = "ReWriteRule ^#newlinkalias#$ index.cfm?action=viewcategory&category=#categoryid#">
   <cffile action = "append" file="#variables.catalogpath#.htaccess" output="#newline#" addnewline="yes" charset="utf-8">
  </cfoutput>
</cffunction>

Open in new window


This way i'm adding each row in a new line in the htaccess file.
Is there any way to 1) create the content with all the rewriterules2) and append it to the document?
I tried to use the query inside a cfsavecontent but i can't get the rewriterules in new lines.

Any help?
0
Panos
Asked:
Panos
  • 3
  • 2
1 Solution
 
_agx_Commented:
If I'm understanding correctly, the problem is new lines are o/s dependent.  

* On windows it's: chr(13) & chr(10)  and Unix its:  chr(10)
* If you have createObject access, you can use System.getProperty("line.separator") instead.

So you can use cfsavecontent .. but it preserves all white space, so you may need to put it all on the same line. Something like this:

Edit - Add final write to disk
...
<cfset var content = "">
<cfset var newLine = chr(13)&chr(10)>
<cfsavecontent variable="content">
 <cfoutput query="geturlrwcategories">ReWriteRule ^#newlinkalias#$ index.cfm?action=viewcategory&category=#categoryid##newLine#</cfoutput>
</cfsavecontent>
<!--- overwrite existing file --->
<cffile action="write" file="#variables.catalogpath#.htaccess" output="#newline#" charset="utf-8">

Open in new window

0
 
PanosAuthor Commented:
Thank you agx.
It is working
0
 
PanosAuthor Commented:
regards
panos
0
 
_agx_Commented:
Correction for the archives.  That very last line:

     <cffile action="write" file="#variables.catalogpath#.htaccess"
            output="#newline#" charset="utf-8">

should be this instead:

     <cffile action="write" file="#variables.catalogpath#.htaccess"
            output="#content#" charset="utf-8">
0
 
PanosAuthor Commented:
Thank you agx.
I have allready correct this.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now