1

quoted_printable_encode()と [quoted_prinatble_decode()を使用しようとしていますが、問題は私のサーバーが PHP4 を実行していることです。PHP ドキュメントによると、quoted_printable_encode() は PHP 5 >= 5.3.0 でのみ使用できます。エンコード機能を利用できるように、ハックまたは回避策を知っている人はいますか

4

5 に答える 5

2

docs によると、imap_8bitを使用できますが、php5 へのアップグレードを検討する必要があります。6年以上の歴史があります!

于 2010-12-03T20:23:20.623 に答える
1

サポートとサポートに感謝することはできません。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 

それを機能させます。皆さんが投稿した後、たまたまここに戻って確認したので、残念ながら私はあなたのソリューションをテストしていませんが、上記の機能は完全に機能します!

本当にありがとうございました!

于 2010-12-03T21:57:15.967 に答える
0
    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
于 2013-03-23T22:04:19.633 に答える
0

IMAP モジュールがインストールされていますか? imap_8bit()代わりに使用するのはどうですか?

于 2010-12-03T20:23:02.820 に答える
0

最善の方法は、PHP 5.4 にアップグレードすること です

それが実際にはオプションではない場合は、リンク先のマニュアル ページにいくつかの代替手段があります(imap_8bit()および、ユーザー投稿ノートの代替実装の一部)。

于 2010-12-03T20:23:10.950 に答える