【问题标题】:Make quoted_printable_encode() work on PHP4使quoted_printable_encode() 在PHP4 上工作
【发布时间】:2011-05-19 23:14:54
【问题描述】:

我正在尝试使用 quoted_printable_encode() 和 [quoted_prinatble_decode(),但问题是我的服务器正在运行 PHP4,根据 PHP 文档,quoted_printable_encode() 仅适用于 PHP 5 >= 5.3.0 .有谁知道黑客或解决方法,所以我可以利用编码函数

【问题讨论】:

  • 抱歉不知道怎么帮到你,但你一定要换php5!! php4 相当于计算机年数 100! :)

标签: php php4 quoted-printable


【解决方案1】:

您是否安装了 IMAP 模块?改用imap_8bit() 怎么样?

【讨论】:

    【解决方案2】:

    最好的办法是升级到 PHP 5。4 是 死了

    如果这真的,真的不是一个选项,manual page you link to 有几个替代方案(imap_8bit() 和用户贡献的注释中的一些替代实现)。

    【讨论】:

      【解决方案3】:

      根据文档,您可以使用imap_8bit,但是您确实应该考虑升级到 php5。它已经存在超过 6 年了!

      【讨论】:

        【解决方案4】:

        我非常感谢你们的支持和帮助。我完全同意我们应该升级到 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 
        

        让它工作。大家发帖后我碰巧回到这里,所以很遗憾我没有测试你的解决方案,但上面的功能非常完美!

        再次感谢大家!

        【讨论】:

        • 确保将您的答案标记为已接受 - 我认为可能对其他人有用,并且看到完整的实现很有趣。
        【解决方案5】:
            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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-04-26
          • 1970-01-01
          • 2023-03-15
          • 2014-11-26
          • 1970-01-01
          • 2015-11-10
          相关资源
          最近更新 更多