note 14139 added to function.quoted-printable-decode.php

From: Date: Wed, 18 Jul 2001 17:06:09 +0000
Subject: note 14139 added to function.quoted-printable-decode.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-15544@lists.php.net to get a copy of this message
If you do not have access to imap_* and do not want to use »$message = chunk_split( base64_encode($message) );« because you want to be able to read the »source« of your mails, you might want to try this: (any suggestions very welcome!) function qp_enc($input = "quoted-printable encoding test string", $line_max = 76) { $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); $eol = "\r\n"; $escape = "="; $output = ""; while( list(, $line) = each($lines) ) { //$line = rtrim($line); // remove trailing white space -> no =20\r\n necessary $linlen = strlen($line); $newline = ""; for($i = 0; $i < $linlen; $i++) { $c = substr($line, $i, 1); $dec = ord($c); if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only $c = "=20"; } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required $h2 = floor($dec/16); $h1 = floor($dec%16); $c = $escape.$hex["$h2"].$hex["$h1"]; } if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay $newline = ""; } $newline .= $c; } // end of for $output .= $newline.$eol; } return trim($output); } $eight_bit = "\xA7 \xC4 \xD6 \xDC \xE4 \xF6 \xFC \xDF = xxx yyy zzz \r\n" ." \xA7 \r \xC4 \n \xD6 \x09 "; print $eight_bit."\r\n---------------\r\n"; $encoded = qp_enc($eight_bit); print $encoded; http://www.php.net/manual/en/function.quoted-printable-decode.php

« previous php.notes (#15544) next »