Skip to content

Instantly share code, notes, and snippets.

@mudge
Created May 7, 2009 10:52
Show Gist options
  • Save mudge/108051 to your computer and use it in GitHub Desktop.
Save mudge/108051 to your computer and use it in GitHub Desktop.
Replace non-ASCII characters with their decimal-encoded XML entity.
# Replace non-ASCII characters with their decimal-encoded XML entity.
str.gsub!(/[^\x00-\x7f]/) { |s| "&##{s.unpack("U")[0]};" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment