Import text along with format to display on CFM

Discussion in 'Programming' started by kimimaro, Feb 12, 2009.

  1. #1
    As the title stated I wanted to import the content of .txt files to be displayed on cfm. I can import the text but problem is it is read as a full single line in the cfm. I need the paragraph formatting to be exactly as they were from the txt file. Can CF do this?
     
    kimimaro, Feb 12, 2009 IP
  2. StefanV

    StefanV Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    A text file will have LF or CRLF (chr(10) or chr(13)chr(10)) to mark a new line. In HTML you will need <br />
    Easiest is to simply replace the chr(10) with <br>:
    <cfset myHTMLContent = Replace(txtFileContent,chr(10),'<br />', 'all'>
    You might wanna remove any CR with Replace(txtFileContent,chr(13),'', 'all'>, but it is normally not important.

    Reason why you replace the LF, chr(10) instead of the CR is simply because the LF is always there, the CR is not.
     
    StefanV, Feb 12, 2009 IP