4 Replies Latest reply on Jan 25, 2009 9:19 AM by ntsiii

    Escaping html characters

      Hello all,

      I am creating a flex chat app. This communicates with my own chat server.

      Now I want to know what is the best way to escape characters?

      I send all data in a XML document to the server, so if I type a message: <i>test</i> the text will appear italy, as it is not escaped.

      If I use escape, it will escape to a code that the Text control not is able to read.

      I just want to know which function will replace < in &lt; > in &gt; and & in &amp;.

        • 1. Re: Escaping html characters
          ntsiii Level 3
          Perhaps I have just missed it, but I have not found an htmlEncode function in AS. So i have done this by creating my own encode function using replace. There are examples of that available.

          But, probably the best solution is to escape() the string when you send it to the server, then u n e s c a p e() it when you receive it.

          This is bizarre, the forum software says I have censored words in my post!
          1 person found this helpful
          • 2. Re: Escaping html characters
            ntsiii Level 3
            Yeah, looks like *u n e s c a p e* is a no-no. Is there some meaning to that word that I do not know?
            1 person found this helpful
            • 3. Escaping html characters
              I have tried esc ape and unes cape.

              But these are my results:

              var Str: String = '<foo>rock & roll</foo>';

              Alert.show(esc ape(Str));

              This will come to:

              Thats fine for sending data, but putting it back with un esc ape will just give me the original back (as expected).

              But I want my < to be &lt; or the equivelant ascii code &#100;

              In PHP you use htmlentities or htmlencode, but in Flex is a mystery.

              Sorry, didn't read your post properly, I think I will have to come up with my own replace function then :(
              • 4. Escaping html characters
                ntsiii Level 3
                google it, you will find examples.