# HTMLCodeFormat

Returns HTML escaped string enclosed in `<PRE>` and `</PRE>` tags. All carriage returns are removed from string, and all special characters (> < " &) are escaped.

See also HTMLEditFormat.

### Syntax

    HTMLCodeFormat(string [, version ])

##### string

String being HTML escaped and preformatted.

##### version

The specific HTML version to use in replacing special characters with their entity references. Valid entries are:

- `-1` -- The latest implementation of HTML
- `2.0` -- For HTML 2.0 (Default)
- `3.2` -- For HTML 3.2

### Example

    <!--- This example shows the use of HTMLCodeFormat
    and HTMLEditFormat --->

    <HTML>
    <HEAD>
    <TITLE>
    HTMLCodeFormat Example
    </TITLE>
    </HEAD>

    <BODY BGCOLOR=silver>
    <H3>HTMLCodeFormat Example</H3>

    <FORM ACTION="HTMLcodeformat.cfm" METHOD="POST">
    Try entering a URL for the tag to return in HTMLCodeFormat
    and HTMLEditFormat:
    <INPUT TYPE="Text" size=25 NAME="urladdress"
      VALUE="http://www.allaire.com">

    <INPUT TYPE="Submit" NAME="" VALUE="get page">
    </FORM>

    <!--- sets a default value for a url to retrieve --->
    <CFPARAM NAME="urladdress" DEFAULT="http://localhost/cfdocs/index.htm">

    <!--- if we have passed a url address in the FORM, we
    want to display the passed address --->
    <CFIF IsDefined("FORM.urladdress") is True>
    <!--- do simple error check to avoid crashing the tag --->
        <CFIF Trim(Form.urladdress) is "" or Trim(Form.urladdress) is "http:/
    /">
    <!--- if error condition tripped, set alternative --->
            <CFSET urlAddress ="http://localhost/cfdocs/index.htm">
            <H4>because you entered no url or an empty string, the tag
            will return the following address: http://localhost/cfdocs/
    index.htm</H4>
        <CFELSE>
    <!--- otherwise use address passed from form --->
            <CFSET urlAddress = FORM.urladdress>
        </CFIF>
    <!--- now use the CFHTTP tag to get the file content
    represented by urladdress --->
            <CFHTTP URL="#urladdress#"
                METHOD="GET"
                RESOLVEURL=YES>
            </CFHTTP>

    <CFELSE>
    <!--- the first time through, retrieve a URL that we know exists --->
    <CFHTTP URL="http://localhost/cfdocs/index.htm"
        METHOD="GET"
        RESOLVEURL=YES>
    </CFHTTP>
    </CFIF>

    <!--- Now, output the file, including the mimetype and content --->
    <H3>Show the file</H3>

    <CFOUTPUT>
    <P>Here is an example of 255 characters from your file
    output in HTMLCodeFormat:
    <P>#HTMLCodeFormat(Mid(CFHTTP.FileContent,1,255))#

    <P>Here is an example of 255 characters from your file
    output in HTMLEditFormat:
    <P>#HTMLEditFormat(Mid(CFHTTP.FileContent,1,255))#
    </CFOUTPUT>

    </BODY>
    </HTML>