5 Replies Latest reply on Mar 13, 2008 8:21 AM by TiGGi

    converting characters

    TiGGi Level 1
      I've tried bunch of string functions but I couldn't get it to work, I am trying to convert something like:
      None &amp;lt;/div&amp;gt; INTO None &</div&>
      so it would display correctly on the page.
      Is my only option that's left Replace or is there an actual function that would do this?
        • 1. Re: converting characters
          Level 7
          TiGGi wrote:
          > I've tried bunch of string functions but I couldn't get it to work, I am trying
          > to convert something like:
          > None &amp;lt;/div&amp;gt; INTO None &</div&>
          > so it would display correctly on the page.
          > Is my only option that's left Replace or is there an actual function that
          > would do this?
          >


          Which way are you trying to get to display. I would expect the first
          example to display correctly in a browser as it is escaped. Are you
          trying to escape mark up do that is displays the code or to un-escaped
          the content so that it is rendered or just display the output?
          • 2. Re: converting characters
            TiGGi Level 1
            I would like it to display as un-escaped, so it will only show text and not html code.
            • 3. Re: converting characters
              Level 7
              TiGGi wrote:
              > I would like it to display as un-escaped, so it will only show text and not html code.


              Sorry, I am not aware of any built-in reverse to the HTMLeditFormat()
              and HTMLcodeFormat() functions. You might try the cflib.org site to see
              if anybody has created one already. Otherwise show you code and we can
              try and help you role your own solution.

              • 4. Re: converting characters
                ssawka Level 1
                You can use ReplaceList to get it to replace the escape characters, something like:

                str=ListReplace(str,"&amp;,&gt;,&lt;","&,>,<")

                You can expand the lists to include all special characters. You'll also have to run the code multiple times, given your example. The first time you run it &amp;lt;/div&amp;gt; will get converted to &lt;/div&gt; The second time you should get </div>. To run it multiple times, you can use a while loop with a regular expression. Something like:

                <cfloop condition="ReFind('\&[^;\s]+\;',str, 0, 0)"></cfloop>

                Forgive me if the code is not exactly right, I didn't test it, but you should get the idea.
                • 5. Re: converting characters
                  TiGGi Level 1
                  Thank you for your help!