January 7th, 2011 by Adrian
Here is a little tool that I have made which can be used to encode and decode strings into URL escape sequences (eg. convert special characters so they are safe to transmit in a query string). I recently also had the need to encode and decode HTML named entity references (eg. ” becomes ”) and after a long hunt around the web I couldn’t find one in AS3. So I have also written a static class called HTMLEntities which has the public methods ‘encode’ and ‘decode’. Hopefully you will find it useful. All the source code is available below.
NOTE: If you use the HTMLEntities class, you may want to remove the entry for the apostrophe (‘) which encodes it as ' because it is not supported by Internet Explorer. Apostrophes are better off being encoded as '
Here are some useful lists of the HTML Named Entities …
- w3schools – HTML ISO-8859-1 Reference
- w3schools – HTML Symbol Entities Reference
- Wikipedia – List of XML and HTML character entity references
- FileFormat – HTML Entity Names
- Webmonkey – Special Characters
And these are handy conversion tools …