Advertisement
Ruslan_Rayanov

str_htmlEncode

Sep 15th, 2022
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. ALTER FUNCTION [dbo].[str_htmlEncode]
  2. (
  3. @UnEncoded as varchar(max)
  4. )
  5. RETURNS varchar(max)
  6. AS
  7. BEGIN
  8. DECLARE @Encoded as varchar(max)
  9.  
  10. --order is important here. Replace the amp first, then the lt and gt.
  11. --otherwise the &lt will become <
  12. SELECT @Encoded =
  13. Replace(
  14. Replace(
  15. Replace(@UnEncoded,'&','&'),
  16. '<', '&lt;'),
  17. '>', '&gt;')
  18.  
  19. RETURN @Encoded
  20. END
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement