Java HTML Encode htmlEncode(String input)

Here you can find the source of htmlEncode(String input)

Description

HTML-encode a string.

License

Open Source License

Parameter

Parameter Description
input the String to convert

Return

a new String with HTML encoded characters

Declaration

public static String htmlEncode(String input) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   w w w  .  j  a va 2 s .com*/
     * HTML-encode a string. This simple method only replaces the five characters &, <, >, ", and '.
     * 
     * @param input the String to convert
     * @return a new String with HTML encoded characters
     */
    public static String htmlEncode(String input) {
        String output = input.replaceAll("&", "&amp;");
        output = output.replaceAll("<", "&lt;");
        output = output.replaceAll(">", "&gt;");
        output = output.replaceAll("\"", "&quot;");
        output = output.replaceAll("'", "&#039;");
        return output;
    }
}

Related

  1. htmlEncode(final String source, StringBuffer target)
  2. htmlEncode(Object input)
  3. htmlEncode(String html)
  4. htmlEncode(String html)
  5. htmlEncode(String input)
  6. HTMLEncode(String s)
  7. htmlEncode(String s)
  8. htmlEncode(String s)
  9. htmlEncode(String s)