AS3 Unescape HTML (inc. common Entity Names - But not all)


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import flash.text.TextField;
  2.  
  3. var myStr:String = "&%20<%20>%20"%20'%20£%20©%20%AE";
  4.  
  5. function htmlUnescape($str:String):String
  6. {
  7. var tf:TextField = new TextField();
  8. tf.htmlText = unescape($str);
  9. return tf.text;
  10. }
  11.  
  12. trace(myStr);
  13. trace(htmlUnescape(myStr));
  14.  
  15. // OUTPUT
  16. // &%20<%20>%20"%20'%20£%20©%20%AE
  17. // & < > " ' £ © ®
  18.  
  19. // This doesn't work for a lot of the other HTML Entity Names.
  20. // For example, &pound; and &copy; don't work.
  21. // See here for a list of HTML Entity Names ...
  22. // http://www.adrianparr.com/download/Special%20Characters%20Cheat%20Sheet.pdf
  23. //
  24. // For a full working class that supports ALL HTML Entity Names see here ...
  25. // http://snipplr.com/view/46566/as3-encode-and-decode-html-entity-names-full-set/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.