2010-12-03 8 views
1

Ich versuche, die quoted_printable_encode() und [quoted_prinatble_decode() zu verwenden, aber das Problem ist mein Server läuft PHP4, und gemäß der PHP-Dokumentation, ist quoted_printable_encode() nur auf PHP 5 verfügbar > = 5.3.0. Kennt jemand einen Hack oder Workaround, so könnte ich die encode func verwendenMachen Sie quoted_printable_encode() Arbeit an PHP4

+2

Sorry, ich weiß nicht, wie ich Ihnen helfen kann, aber Sie sollten definitiv zu php5 wechseln !! php4 ist wie 100 in Computerjahren! :) – Trufa

Antwort

0

Haben Sie das IMAP-Modul installiert? Was ist mit der Verwendung von imap_8bit() stattdessen?

0

Das beste, was zu tun wäre, wäre ein Upgrade auf PHP 5. 4 ist tot.

Wenn das wirklich, wirklich keine Option ist, hat die manual page you link to ein paar Alternativen (imap_8bit() und einige alternative Implementierungen in den Benutzer beigetragenen Notizen).

2

Laut der Dokumentation könnten Sie imap_8bit verwenden, aber Sie sollten wirklich erwägen, auf PHP5 zu aktualisieren. Es ist schon seit über 6 Jahren!

1

Ich kann Ihnen nicht genug danken für die Unterstützung und Hilfe. Ich stimme völlig zu, dass wir auf PHP5 upgraden sollten - aber das ist für die große Firma, für die ich arbeite, und wie viele von euch wissen, gibt es bestimmte Dinge, die passieren sollten, aber nicht oder nicht. Ich bin nur ein Praktikant, sowieso, also werde ich tun, was sie sagen =)

ich es herausgefunden -

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 

macht es funktionieren. Ich habe zufällig hier nachher nachgeschaut, also habe ich deine Lösungen leider nicht getestet, aber die obige Funktion funktioniert einfach perfekt!

Vielen Dank noch einmal!

+1

stellen Sie sicher, dass Sie Ihre Antwort als akzeptiert markieren - könnte für jemand anderen nützlich sein, denke ich, und interessant, um eine vollständige Implementierung zu sehen. – Hamish

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 
Verwandte Themen