Skip to content

Instantly share code, notes, and snippets.

@seancribbs
Created February 16, 2009 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seancribbs/64915 to your computer and use it in GitHub Desktop.
Save seancribbs/64915 to your computer and use it in GitHub Desktop.
h(Text) ->
html_escape(Text).
html_escape("") -> "";
html_escape(Text) ->
WithoutAmp = re:replace(Text, "&", "\\&", [global, {return, list}]),
WithoutLt = re:replace(WithoutAmp, "<", "\\&lt;", [global, {return, list}]),
WithoutGt = re:replace(WithoutLt, ">", "\\&gt;", [global, {return, list}]),
re:replace(WithoutGt, "\"", "\\&quot;", [global, {return, list}]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment