Java HTML Encode htmlEncode(String txt)

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

Description

Encodes the given text to HTML save form.

License

Open Source License

Declaration

public static String htmlEncode(String txt) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   ww  w.j  av  a 2s. co m
     * Encodes the given text to HTML save form.
     */
    public static String htmlEncode(String txt) {
        if (txt == null) {
            return "";
        }
        return txt.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;")
                .replace("'", "&#39;").replace("\r\n", "<br/>").replace("\n", "<br/>");
    }
}

Related

  1. htmlEncode(String string)
  2. HtmlEncode(String strInput)
  3. htmlEncode(String strSrc)
  4. htmlEncode(String strSrc)
  5. htmlEncode(String text)
  6. htmlEncode(String txt)
  7. htmlEncoded(String text)
  8. htmlEncoder(String content)
  9. htmlEncoding(String str)