使引用的\u可打印\u encode()在PHP4上工作

使引用的\u可打印\u encode()在PHP4上工作,php,php4,quoted-printable,Php,Php4,Quoted Printable,我试图使用and[quoted_prinatable_decode(),但问题是我的服务器运行的是PHP4,根据PHP文档,quoted_printable_encode())仅在PHP5>=5.3.0上可用。是否有人知道有黑客攻击或解决方法,以便我可以使用encode func您是否安装了IMAP模块?使用IMAP_8bit()如何?最好的办法是升级到PHP5.4 死了 如果这真的不是一个选项,那么有几个备选方案(以及用户提供的说明中的一些备选实现)根据文档,你可以使用,但是你确实应该考虑升级

我试图使用and[quoted_prinatable_decode(),但问题是我的服务器运行的是PHP4,根据PHP文档,quoted_printable_encode())仅在PHP5>=5.3.0上可用。是否有人知道有黑客攻击或解决方法,以便我可以使用encode func

您是否安装了IMAP模块?使用
IMAP_8bit()
如何?

最好的办法是升级到PHP5.4 死了


如果这真的不是一个选项,那么有几个备选方案(以及用户提供的说明中的一些备选实现)根据文档,你可以使用,但是你确实应该考虑升级到PHP5。它已经存在超过6年了。

< P>我不能对你的支持和帮助表示感谢。我完全同意我们应该升级到PHP5——但是这是为我所工作的大公司,而且你们中的很多人知道,有一些东西是寿。我会的,但不做也不行。反正我只是个实习生,所以我要照他们说的去做

我想出来了-

function quoted_printable_encode($input, $line_max = 75) {                  // Quoted_printable_encode that works with php 4.x
   $hex = array('0','1','2','3','4','5','6','7', 
                          '8','9','A','B','C','D','E','F'); 
   $lines = preg_split("/(?:\r\n|\r|\n)/", $input); 
   $linebreak = "=0D=0A=\r\n"; 
   /* the linebreak also counts as characters in the mime_qp_long_line 
    * rule of spam-assassin */ 
   $line_max = $line_max - strlen($linebreak); 
   $escape = "="; 
   $output = ""; 
   $cur_conv_line = ""; 
   $length = 0; 
   $whitespace_pos = 0; 
   $addtl_chars = 0; 

   // iterate lines 
   for ($j=0; $j<count($lines); $j++) { 
     $line = $lines[$j]; 
     $linlen = strlen($line); 

     // iterate chars 
     for ($i = 0; $i < $linlen; $i++) { 
       $c = substr($line, $i, 1); 
       $dec = ord($c); 

       $length++; 

       if ($dec == 32) { 
          // space occurring at end of line, need to encode 
          if (($i == ($linlen - 1))) { 
             $c = "=20"; 
             $length += 2; 
          } 

          $addtl_chars = 0; 
          $whitespace_pos = $i; 
       } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { 
          $h2 = floor($dec/16); $h1 = floor($dec%16); 
          $c = $escape . $hex["$h2"] . $hex["$h1"]; 
          $length += 2; 
          $addtl_chars += 2; 
       } 

       // length for wordwrap exceeded, get a newline into the text 
       if ($length >= $line_max) { 
         $cur_conv_line .= $c; 

         // read only up to the whitespace for the current line 
         $whitesp_diff = $i - $whitespace_pos + $addtl_chars; 

        /* the text after the whitespace will have to be read 
         * again ( + any additional characters that came into 
         * existence as a result of the encoding process after the whitespace) 
         * 
         * Also, do not start at 0, if there was *no* whitespace in 
         * the whole line */ 
         if (($i + $addtl_chars) > $whitesp_diff) { 
            $output .= substr($cur_conv_line, 0, (strlen($cur_conv_line) - 
                           $whitesp_diff)) . $linebreak; 
            $i =  $i - $whitesp_diff + $addtl_chars; 
          } else { 
            $output .= $cur_conv_line . $linebreak; 
          } 

        $cur_conv_line = ""; 
        $length = 0; 
        $whitespace_pos = 0; 
      } else { 
        // length for wordwrap not reached, continue reading 
        $cur_conv_line .= $c; 
      } 
    } // end of for 

    $length = 0; 
    $whitespace_pos = 0; 
    $output .= $cur_conv_line; 
    $cur_conv_line = ""; 

    if ($j<=count($lines)-1) { 
      $output .= $linebreak; 
    } 
  } // end for 

  return trim($output); 
} // end quoted_printable_encode 
function quoted\u printable\u encode($input,$line\u max=75){//quoted\u printable\u encode,可与PHP4.x一起使用
$hex=数组('0'、'1'、'2'、'3'、'4'、'5'、'6'、'7',
‘8’、‘9’、‘A’、‘B’、‘C’、‘D’、‘E’、‘F’;
$lines=preg_split(“/(?:\r\n |\r |\n)/”,$input);
$linebreak=“=0D=0A=\r\n”;
/*换行符也算作mime_qp_long_行中的字符
*垃圾邮件刺客规则*/
$line_max=$line_max-strlen($linebreak);
$escape=“=”;
$output=“”;
$cur_conv_line=“”;
$length=0;
$whitespace_pos=0;
$addtl_chars=0;
//迭代行
对于($j=0;$j 126)){
$h2=下限($dec/16);$h1=下限($dec%16);
$c=$escape.$hex[“$h2”]。$hex[“$h1”];
$length+=2;
$addtl_chars+=2;
} 
//超出了换行文字的长度,请在文本中换行
如果($length>=$line_max){
$cur_conv_line.=$c;
//只读至当前行的空白
$whitesp_diff=$i-$whitespace_pos+$addtl_chars;
/*必须阅读空格后的文本
*再次(+输入的任何其他字符)
*由于编码过程在空白之后而存在)
* 
*另外,如果文件中有*无*空格,则不要从0开始
*全线*/
如果($i+$addtl_chars)>$whitesp_diff){
$output.=substr($cur_conv_line,0)(strlen($cur_conv_line)——
$whitesp_diff)).$linebreak;
$i=$i-$whitesp_diff+$addtl_chars;
}否则{
$output.=$cur\u conv\u line.$linebreak;
} 
$cur_conv_line=“”;
$length=0;
$whitespace_pos=0;
}否则{
//未达到换行字的长度,请继续阅读
$cur_conv_line.=$c;
} 
}//结束
$length=0;
$whitespace_pos=0;
$output.=$cur\u conv\u line;
$cur_conv_line=“”;

如果($jSorry不知道如何帮助你,但你肯定应该改成php5!!php4在计算机时代就像100!:)请确保你将你的答案标记为已接受-我认为,这可能对其他人有用,而且看到完整的实现也很有趣。
    public function quoted_printable($mesg){
  $orders = unpack("C*", $mesg);
  unset($mesg);
  array_filter($orders, array($this, 'cb_qp'));
  return implode($orders);
}

// Quoted-Printable Callback
private function cb_qp(&$byte){
  $byte = ($byte > 126 || $byte == 61 || $byte == 37) ? sprintf('=%X', $byte) : pack("C", $byte);
}
 // http://rolfrost.de/proglog.html?d=20130324