Tatva-Artha

meaning of "it"

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!

http://www.tatvartha.com/wp-content/plugins/sociofluid/images/digg_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/reddit_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/stumbleupon_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/delicious_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/google_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/twitter_16.png

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Written by admin

May 21st, 2009 at 2:19 pm

Posted in All

Tagged with , ,

Leave a Reply