<?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; quoted-printable</title>
	<atom:link href="http://blog.chacuo.net/tag/quoted-printable/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.chacuo.net</link>
	<description>web原理、web架构、web安全、web性能、服务器性能、服务器架构、服务器安全;你不能预知明天，但你可以利用今天。你不能样样顺利，但你可以事事尽力!</description>
	<lastBuildDate>Mon, 31 Aug 2020 15:33:40 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Quoted-printable 编码介绍、编码解码转换</title>
		<link>http://blog.chacuo.net/494.html</link>
		<comments>http://blog.chacuo.net/494.html#comments</comments>
		<pubDate>Wed, 24 Jul 2013 11:59:18 +0000</pubDate>
		<dc:creator>程默</dc:creator>
				<category><![CDATA[web原理]]></category>
		<category><![CDATA[quoted-printable]]></category>
		<category><![CDATA[字符编码]]></category>

		<guid isPermaLink="false">http://blog.chacuo.net/?p=494</guid>
		<description><![CDATA[Quoted-printable 可译为“可打印字符引用编码”、“使用可打印字符的编码”，我们收邮件，查看信件 [...]]]></description>
				<content:encoded><![CDATA[<p>Quoted-printable 可译为“可打印字符引用编码”、“使用可打印字符的编码”，我们收邮件，查看信件原始信息，经常会看到这种类型的编码！</p>
<blockquote><pre><a href="http://blog.chacuo.net/wp-content/uploads/2013/07/image8.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Quoted-printable编码" border="0" alt="Quoted-printable编码" src="http://blog.chacuo.net/wp-content/uploads/2013/07/image_thumb8.png" width="547" height="296"></a></pre>
<pre>最多时候，我们在邮件头里面能够看到这样的编码！Content-Transfer-Encoding:quoted-printable</pre>
<pre>&nbsp;</pre>
</blockquote>
<p>它是<b>多用途互联网邮件扩展</b>（MIME) 一种实现方式。其中MIME是一个互联网标准，它扩展了电子邮件标准，致力于使其能够支持非ASCII字符、二进制格式附件等多种格式的邮件消息。目前http协议中，很多采用MIME框架！quoted-printable 就是说用一些可打印常用字符，表示一个字节（8位）中所有非打印字符方法！</p>
<p><strong>Quoted-printable编码方法</strong></p>
<blockquote>
<p>任何一个8位的字节值可编码为3个字符：一个等号&#8221;=&#8221;后跟随两个十六进制数字(0–9或A–F)表示该字节的数值.例如，ASCII码换页符（十进制值为12）可以表示为&#8221;=0C&#8221;, 等号&#8221;=&#8221;（十进制值为61）必须表示为&#8221;=3D&#8221;. 除了可打印ASCII字符与换行符以外，所有字符必须表示为这种格式.</p>
<p>所有可打印ASCII字符(十进制值的范围为33到126)可用ASCII字符编码来直接表示, 但是等号&#8221;=&#8221;(十进制值为61)不可以这样直接表示.ASCII的水平制表符(tab)与空格符, 十进制为9和32, 如果不出现在行尾则可以用其ASCII字符编码直接表示。如果这两个字符出现在行尾，必须QP编码表示为&#8221;=09&#8243; (tab)或&#8221;=20&#8243; (space).</p>
<p>如果数据中包含有意义的行结束标志，必须转换为ASCII回车(CR)换行(LF)序列，既不能用原来的ASCII字符也不能用QP编码的&#8221;=&#8221;转义字符序列。 相反，如果字节值13与10有其它的不是行结束的含义，它们必须QP编码为=0D与=0A.</p>
<p>quoted-printable编码的数据的每行长度不能超过76个字符. 为满足此要求又不改变被编码文本，在QP编码结果的每行末尾加上软换行(soft line break). 即在每行末尾加上一个&#8221;=&#8221;, 但并不会出现在解码得到的文本中. </p>
<p>例如：If you believe that truth=beauty, then surely mathematics is the most beautiful branch of philosophy. 编码后结果是</p>
<pre>If you believe that truth=3Dbeauty, then surely=20=
mathematics is the most beautiful branch of philosophy.</pre>
</blockquote>
<p>编码里面，有几个特定限定，一些可打印字符不用编码，当然如果你按照规范编码后，也一样可以显示的！因此自己简单自己实现该编码:</p>
<blockquote><pre>function quoted_printable_encode($string) { <br />&nbsp;&nbsp;&nbsp; return preg_replace('/[^\r\n]{73}[^=\r\n]{2}/', "$0=\r\n", str_replace("%","=",<br />rawurlencode($string))); <br />} </pre>
<p>一个函数就可以，将所有字符串urlencode转换后，%号替换为”=”号，然后对非\r\n超过73连续字符，后面加一个=\r\n。这个是简单实现方法！ 按照该编码详细说明里面，有些空格、换行，还有一些特殊字符可以不用转换。不过一起转换了，也不会有影响！</p>
</blockquote>
<p>很多时候，我们用些常见字符表示所有8位其它非打印字符，这种通过，Quoted-printable编码，只是对该字节转为16进制后，做简单增加前缀！然后做些特殊字符处理即可！ 它的简单，及编码高效，也让该编码在邮件格式里面，得到了广泛使用！好了，就到这里，欢迎交流！</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chacuo.net/494.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
