quoted-printable decode

Quoted-Printable
    Quoted-Printable简称QP, 一般用在Email系统中。它通常用于少量文本方式的8位字符的编码,例如 Foxmail 就用它做对主题和信体的编码。
    QP的算法可以说是最简单的也可以说是编码效率最低的(它的编码率是1 :3 ),它是专门为了处理 8位字符制定的。它的算法是:读一个字符,如果ASCII码大于127,即字符的第8位是1的话,进行编码,否则忽略(有时也对7位字符编码)。编码很简单,看下面的C语言描述即可:
/*QP编码*/
void qp(unsigned char sour,unsigned char first,unsigned char second)
/* 
 sour:要编码的字符
  first: 编码后的第一个字符
   second: 编码后的第二个字符
 first和second为返回值
*/
{
 if(sour>127)  
 {first=sour>>4;
 second=sour&15;
 if(first>9) first+=55;
 else first+=48;
 if(second>9) second+=55;
 else second+=48;
  printf ("%c%c%c",'=',first,second);
 }
}
 
/*QP解码*/
void uqp(unsigned char sour,unsigned char first,unsigned char second)
/*
 sour:解码后的字符
 first: QP 码的第一个字符
   second:QP码的第二个字符
 sour为返回值
*/
{
 if(first>=65) first-=55;
 else first-=48;
 if(second>=65) second-=55;
 else second-=48;
 sour=NULL;
 sour=first<<4;
 sour|=second;
}
  关于QP的详细说明和准确定义可以参阅RFC2045。
在PHP中以下函数可以用来解码显示quoted-printable编码内容

quoted_printable_decode

(PHP 3 >= 3.0.6, PHP 4, PHP 5)

quoted_printable_decode --  Convert a quoted-printable string to an 8 bit string

Description

string quoted_printable_decode ( string str )

This function returns an 8-bit binary string corresponding to the decoded quoted printable string (according to RFC2045, section 6.7, not RFC2821, section 4.5.2, so additional periods are not stripped from the beginning of line). This function is similar to imap_qprint(), except this one does not require the IMAP module to work.

说明:使用这个函数在PHP4及以上是内部函数,功能类似于imap_qprint(),但是不需要导入IMAP模块

例子:

<?php

echo quoted_printable_decode ("=E6=B5=8B=E8=AF=95=E8=80=85");

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值