<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>网络编程 &#187; url解码　url编码</title>
	<atom:link href="http://www.sdgz.cn/tag/url%e8%a7%a3%e7%a0%81%e3%80%80url%e7%bc%96%e7%a0%81/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sdgz.cn</link>
	<description>PHP RUBY</description>
	<lastBuildDate>Tue, 03 Aug 2010 17:14:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>ruby的url解码函数和url编码函数</title>
		<link>http://www.sdgz.cn/ruby-of-the-url-decoding-function-and-url-encoding-function/</link>
		<comments>http://www.sdgz.cn/ruby-of-the-url-decoding-function-and-url-encoding-function/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 11:08:18 +0000</pubDate>
		<dc:creator>leleba</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[url解码　url编码]]></category>

		<guid isPermaLink="false">http://www.sdgz.cn/ruby-of-the-url-decoding-function-and-url-encoding-function/</guid>
		<description><![CDATA[含中文字符的url是一些乱码，如中文&#8221;个&#8221;，在url中表示为&#8221;％b8%f6&#8243;。有时需要进行url解码和编码，两个函数如下： def URLDecode(str) str.gsub!(/%[a-fA-F0-9]{2}/) { &#124;x&#124; x = x[1..2].hex.chr } end def URLEncode(str) str.gsub!(/[^\w$&#38;\-+.,\/:;=?@]/) { &#124;x&#124; x = format(&#8220;%%%x&#8220;, x[0]) } end]]></description>
			<content:encoded><![CDATA[<p>含中文字符的url是一些乱码，如中文&#8221;个&#8221;，在url中表示为&#8221;％b8%f6&#8243;。有时需要进行url解码和编码，两个函数如下：</p>
<p><span style="COLOR: green">def</span> <span style="COLOR: blue">URLDecode</span><span style="COLOR: olive">(</span><span style="COLOR: blue">str</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br/></span> <span style="COLOR: blue">str</span><span style="COLOR: gray">.</span><span style="COLOR: blue">gsub</span><span style="COLOR: gray">!</span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">/</span><span style="COLOR: red">%[a-fA-F0-9]{2}</span><span style="COLOR: #8b0000">/</span><span style="COLOR: olive">)</span> <span style="COLOR: gray">{ |</span><span style="COLOR: blue">x</span><span style="COLOR: gray">|</span> <span style="COLOR: blue">x</span> <span style="COLOR: gray">=</span> <span style="COLOR: blue">x</span><span style="COLOR: olive">[</span><span style="COLOR: maroon">1..2</span><span style="COLOR: olive">]</span><span style="COLOR: gray">.</span><span style="COLOR: blue">hex</span><span style="COLOR: gray">.</span><span style="COLOR: blue">chr</span> <span style="COLOR: gray">} <br/></span><span style="COLOR: green">end</span><span style="COLOR: gray"><br/><br/></span> <span style="COLOR: green">def</span> <span style="COLOR: blue">URLEncode</span><span style="COLOR: olive">(</span><span style="COLOR: blue">str</span><span style="COLOR: olive">)</span><span style="COLOR: gray"><br/></span> <span style="COLOR: blue">str</span><span style="COLOR: gray">.</span><span style="COLOR: blue">gsub</span><span style="COLOR: gray">!</span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">/</span><span style="COLOR: red">[^</span><span style="COLOR: navy">\w</span><span style="COLOR: red">$&amp;</span><span style="COLOR: navy">\-</span><span style="COLOR: red">+.,</span><span style="COLOR: navy">\/</span><span style="COLOR: red">:;=?@]</span><span style="COLOR: #8b0000">/</span><span style="COLOR: olive">)</span> <span style="COLOR: gray">{ |</span><span style="COLOR: blue">x</span><span style="COLOR: gray">|</span> <span style="COLOR: blue">x</span> <span style="COLOR: gray">=</span> <span style="COLOR: blue">format</span><span style="COLOR: olive">(</span><span style="COLOR: #8b0000">&#8220;</span><span style="COLOR: red">%%%x</span><span style="COLOR: #8b0000">&#8220;</span><span style="COLOR: gray">,</span> <span style="COLOR: blue">x</span><span style="COLOR: olive">[</span><span style="COLOR: maroon">0</span><span style="COLOR: olive">])</span> <span style="COLOR: gray">} <br/></span><span style="COLOR: green">end</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sdgz.cn/ruby-of-the-url-decoding-function-and-url-encoding-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

