Java String to HTML Entities Encoder

The following is a handy Java utility method to encode a plain text string into appropriate HTML entities. This method is similar to the htmlentities function in PHP. This method only encodes some of the more common characters to the equivalent HTML entity name while the rest are encoded as HTML entity numbers.

Leave a Comment