Posted By

Scooter on 09/11/10


Tagged


Versions (?)

Add and strip slashes


 / Published in: VB.NET
 

URL: http://reusablecode.blogspot.com/2009/02/add-and-strip-slashes.html

VB.NET implementation on the PHP functions by the same name, but with support for more problematic characters.

  1. <%
  2. ' Copyright (c) 2010, 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. ' Despite the identical naming, these functions are more comprehensive than their PHP equivalents.
  10. ' They go above and beyond even mysql_real_escape_string(), by including support for backspace and horizontal tab.
  11.  
  12. ' List of characters handled:
  13. ' \000 null
  14. ' \010 backspace
  15. ' \011 horizontal tab
  16. ' \012 new line
  17. ' \015 carriage return
  18. ' \032 substitute
  19. ' \042 double quote
  20. ' \047 single quote
  21. ' \134 backslash
  22. ' \140 grave accent
  23.  
  24. ' Returns a string with backslashes before characters that need to be quoted in database queries
  25. function addslashes(unsafeString)
  26. addslashes = regEx.replace(unsafeString, "([\000\010\011\012\015\032\042\047\134\140])", "\$1")
  27. end function
  28.  
  29. ' Un-quote string quoted with addslashes()
  30. function stripslashes(safeString)
  31. stripslashes = regEx.replace(safeString, "\\([\000\010\011\012\015\032\042\047\134\140])", "$1")
  32. end function
  33. %>

Report this snippet  

You need to login to post a comment.