Posted By

Scooter on 02/14/09


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

benrudolph
asifrizvigmailcom


htmlspecialchars()


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2009/02/htmlspecialchars.html

ASP implementation of the PHP functions with the same names.

  1. <%
  2. ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.
  3. '
  4. ' This work is licensed under the Creative Commons Attribution License. To view
  5. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  6. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  7. ' 94305, USA.
  8.  
  9. ' Convert special characters to HTML entities.
  10. function htmlspecialchars(someString)
  11. ' Critical that ampersand is converted first, since all entities contain them.
  12. htmlspecialchars = replace(replace(replace(replace(someString, "&", "&amp;"), ">", "&gt;"), "<", "&lt;"), """", "&quot;")
  13. end function
  14.  
  15. ' Convert HTML entities to special characters.
  16. function htmlspecialchars_decode(someString)
  17. htmlspecialchars_decode = replace(replace(replace(replace(someString, "&amp;", "&"), "&gt;", ">"), "&lt;", "<"), "&quot;", """")
  18. end function
  19. %>

Report this snippet  

You need to login to post a comment.