Tatva-Artha

meaning of "it"

Archive for the ‘html’ tag

CGI escape, unescape, escapeHTML, unescapeHTML

without comments

I just can’t seem to remember which to use when so here are the 4 great helpers when working with URLs and HTML:

When constructing URLs, you use escape and unescape:

url = "http://site.com/?address=" + CGI.escape("123 Main St, City, ST, 99999")
# url: http://example.com/?address=123+Main+St%2C+City%2C+ST%2C+99999

unescape does the reverse.

When rendering text inside HTML page, you use escapeHTML and unescapeHTML:

raw_html = CGI::escapeHTML("<div>An example HTML to be displayed raw on an HTML page</div>") #raw_html: &lt;div&gt;An example HTML to be displayed raw on an HTML page&lt;/div&gt;

unescapeHTML is for converting an html-escaped string back to proper HTML form.

Simple, but you often forget!

Written by admin

May 21st, 2009 at 2:19 pm

Posted in All

Tagged with , ,