Skip to content

Instantly share code, notes, and snippets.

@azcoov
Created August 16, 2011 07:01
Show Gist options
  • Save azcoov/1148579 to your computer and use it in GitHub Desktop.
Save azcoov/1148579 to your computer and use it in GitHub Desktop.
SQL HTML Encoding
create function dbo.fn_HtmlEncode (
@Html as varchar ( max )
)
returns varchar ( max )
as
/*
select dbo.fn_HtmlEncode('<This is a T&st #>')
*/
begin
declare @encoded as varchar ( max )
select @encoded =
replace (
replace (
replace (
replace (
replace ( @Html, '&' , '&amp;' ),
'<' , '&lt;' ),
'>' , '&gt;' ),
' ' , '+' ),
'#' , '%23' )
return @encoded
end
go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment